When calling std::regex_match(), “groups” (things inside parentheses) will be returned in std::smatch.
This is great, except that this causes stack overflow in many cases due to how it is implemented in Microsoft® Visual Studio™.
I only want to match the start of the string, but std::regex_match() matches the whole string.
In order to get around this, I postfix my pattern with “.*”.
This fails to catch \r and \n, but otherwise works.
So I change it to “(.|[\r\n])*”
Now here is the problem. Because I have added (), it is now a match that will be returned to std::smatch, which means it goes recursive for every trailing character until the end of the file.
Thus, on long files, it causes stack-overflow. “.*” works on any-sized files as it does not evaluate the rule recursively.
Temporarily I have removed \r and \n from the input and gone back to using “.*”, but I need a better solution.
There are several ways in which I could get around this, if only one of them is possible.
#1: This might be just because it is trying to return the contents of the grouping. Is there any way to add () as part of a rule, but to not have it in std::smatch?
#2: Is there a better way to match any character until the end of the input?
#3: Is there a flag or something I have overlooked on std::regex_match() so that I can tell it just to match the start of the input rather than all of the input?
L. Spiro