When a negative lookahead assertion is successful (i.e., the asserted regular expression does not match), some capture groups might be assigned in the asserted regular expression as if the lookahead regular expression had matched.
Test case
#include <iostream>
#include <regex>
using namespace std;
int main() {
const regex re("(?!(a)b)..");
cmatch match;
cout << "'(?!(a)b)..' matches 'ac': "
<< regex_match("ac", match, re)
<< '\n';
cout << "capture group 1 matched: "
<< match[1].matched
<< '\n';
}
https://godbolt.org/z/EzjGrGP5K
This prints:
'(?!(a)b)..' matches 'ac': 1
capture group 1 matched: 1
Expected result
This should print:
'(?!(a)b)..' matches 'ac': 1
capture group 1 matched: 0
It follows from ECMA-262 3rd ed., Section 15.10.2.8 "Atom", that capture groups in negative lookahead assertions are never matched, whether the asserted regular expression matches or not.