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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…