Why will regex "([a-z])((?!\\1)[a-z])" match string "aa" in C++11?
c++, c++11, regex
Solution
Because it was bugged in GCC5. It works as expected in GCC6 and MSVC14.
Problem
Indeed running ``` regex pattern("([a-z])((?!\\1)[a-z])"); cout << regex_match("aa", pattern) << endl; ``` results in the output "1", yet the first group matched is "a", and if instead I run ``` regex pattern("([a-z])((?!a)[a-z])"); cout << regex_match("aa", pattern) << endl; ``` I get "0" as expected. Note that exactly the same regex works as expected in Python 3, i.e. running ``` re.match("([a-z])((?!\\1)[a-z])", "aa") ``` produces no matches. Can someone explain what is happening here? Just for reference, I am using g++ (tdm64-1) 5.1.0 with flags -O2 and -std=c++11.