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"
> gsub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)", "\\5, \\7, \\9, \\10, \\15", test, perl = TRUE)
[1] "e, g, i, a0, a5"
See Regular Expressions with The R Language:
But with PCRE you should be able to use named groups. So try
(?P<name>regex)for groupd naming and(?P=name)as backreference.