如何使用gsub超过9个反向引用?
我希望以下示例中的输出为“e,g,i,j,o”.
我希望以下示例中的输出为“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,a0,a5"
见
Regular Expressions with The R Language:
原文链接:https://www.f2er.com/regex/356604.htmlYou can use the backreferences
\1
through\9
in the replacement text to reinsert text matched by a 07001. There is no replacement text token for the overall match. Place the entire regex in a capturing group and then use\1
.
但是使用PCRE,您应该可以使用named groups.所以尝试(?P< name>正则表达式)用于groupd命名和(?P = name)作为反向引用.