How to use gsub with more than 9 backreferences? I would expect the output in the example below to be \"e, g, i, j, o\".
> test <- \"abcdefghijklmnop\"
&g
See Regular Expressions with The R Language:
You can use the backreferences
\1
through\9
in the replacement text to reinsert text matched by a capturing group. There is no replacement text token for the overall match. Place the entire regex in a capturing group and then use\1
.
But with PCRE you should be able to use named groups. So try (?P<
name
>
regex
)
for groupd naming and (?P=
name
)
as backreference.