Skip to content

<regex>: regex_search() throws regex_error(error_complexity) when a long string is used with a lookahead regex #6347

Description

@TheStormN

Describe the bug

We a trying to upgrade the compiler to the latest MSVC version. First time we did hit this issue #5792. After it was fixed and new MSVC version published, we've upgraded again to 14.51 and now we are getting another issue, this time with regex_error(error_complexity) when a lookahead regex is being used with a really long search string.

Note that if I make the path string shorter, everything is working good. While this might be an expected limitation, we didn't have issues with Visual Studio 2022. Also on Linux with GCC 13 this code is working properly.

Command-line test case

#include <iostream>
#include <regex>

int main()
{
	try {
		std::regex pattern(R"((?:.+[\/\\])?(?:.+?)_(.+?)_(.+?)@(.+?)\.(?:exe|app))");
		std::smatch matches;
		std::string requestStringParams(R"(D:\some\really\long\path\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\myapp.exe https://mysite.com/doaction/?action=56)");
		std::regex_search(requestStringParams, matches, pattern);
		std::cout << "no exception\n";
	}
	catch (const std::regex_error& ex) {
		std::cout << "regex_error with code " << ex.code() << "\n";
	}

	return 0;
}

This prints "regex_error with code 11".

Expected behavior

Should print "no exception".

STL version

Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36248 for x64

Additional context

Might be related to issue #5792 but the exception is with different error code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregexmeow is a substring of homeowner

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions