Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<regex>: Back-references to unmatched capture groups should not match in POSIX basic regular expressions #5374

Open
muellerj2 opened this issue Mar 28, 2025 · 0 comments · May be fixed by #5376
Labels
bug Something isn't working regex meow is a substring of homeowner

Comments

@muellerj2
Copy link
Contributor

Describe the bug

According to Section 9.3.6 of the POSIX standard, back-references to unmatched capture groups ("subexpressions") should not match. However, MSVC STL's implementation currently matches such back-references to the empty string.

Test case

#include <iostream>
#include <regex>
#include <string>

using namespace std;

int main() {
        string pattern = R"(\(.\)*\1)";
        regex re{pattern, regex_constants::basic};
        cout << "regex '"<< pattern
             << "' matches the empty string: "
             << regex_match("", re);
}

https://godbolt.org/z/83nxo39qj

Expected behavior

The regular expression should not match.

Additional context

Note that the equivalent ECMAScript regex (.)*\1 does match the empty string, since the standard says that back-references to unmatched capture groups match the empty string.

@StephanTLavavej StephanTLavavej added bug Something isn't working regex meow is a substring of homeowner labels Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regex meow is a substring of homeowner
Projects
None yet
2 participants