I am currently working on a program that matches certain urls, using regexes. For example, I have this case:
int main()
{
try
{
std::wstring url = L"www.google.com";
std::wregex reg(L"^(?:(?!math|latex).)*\\.?stackexchange.com");
std::regex_search(url, reg);
}
catch (std::regex_error e)
{
std::cout << e.what() << std::endl;
std::cout << e.code() << std::endl;
}
}
Works like a charm, in this case it obviously does not match. But if I use any url string longer than 497 characters, the regex_search function fails. Example:
std::wstring url = L"AAAAA...AAAA"; //498 chars long
e.what()
prints: "regex_error(error_stack): There was insufficient memory to determine wheter the regular expression could match the specified character sequence."
e.code()
prints: 12
It surprises me that the stack size seems to be the problem. After all, 498 chars aren't that much if you think about searching a file or the source code of a website using regexes. Is there any way to fix this in a solid manner, other than delaying the problem to more (maybe 1000) chars? Maybe with a self written allocator? Though I doubt that it's possible to provide any form of allocator that allocates stackframes on the heap. Increasing the stack size isn't a real solution because it just delays the problem.
I am using Visual Studio Community 2017, Version 15.5.6.
This shows that my assumption seems to be correct.
Exact exception: Unhandled exception at 0x76EECBB2 in RegTest.exe: Microsoft C++ exception: std::regex_error at memory location 0x00454FF8.