正则表达式 – gsub()中超过9个反向引用

前端之家收集整理的这篇文章主要介绍了正则表达式 – gsub()中超过9个反向引用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用gsub超过9个反向引用?
我希望以下示例中的输出为“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

You 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)作为反向引用.

原文链接:https://www.f2er.com/regex/356604.html

猜你在找的正则表达式相关文章