I am using pcre2_substitute()
function in my c++ project to perform regex replace:
int ret=pcre2_substitute(
re, /*Points to the compiled pattern*/
subject, /*Points to the subject string*/
subject_length, /*Length of the subject string*/
0, /*Offset in the subject at which to start matching*/
rplopts, /*Option bits*/
0, /*Points to a match data block, or is NULL*/
0, /*Points to a match context, or is NULL*/
replace, /*Points to the replacement string*/
replace_length, /*Length of the replacement string*/
output, /*Points to the output buffer*/
&outlengthptr /*Points to the length of the output buffer*/
);
This is the man page of the function. It doesn't say how many captured groups are possible. I have tested that $01
, ${6}
, $12
works, but what is the limit?
I checked if there's a digit limit like the C++ std::regex
, but there isn't. $000000000000001
works as $1
while in std::regex
it would mean $00
and the rest would be treated as string.
The code I am using for testing is this one. You will need pcre2 library to run this code.
backreferences
, but backreferences are constructs in the regular expression that refer to captured data. On the replacement side, capture buffers are just variables. – Gropius$1234
. That is capture group number1,234
not capture group 1,2,3,4. For a real test, programmatically create a regex with about 10,000 capture groups. Set an appropriate subject string. Then try to do a substitution using $1234. – Gropius