正则表达式 – 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)作为反向引用.

相关文章

jquery.validate使用攻略(表单校验) 目录 jquery.validate...
/\s+/g和/\s/g的区别 正则表达式/\s+/g...
自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母...
this.optional(element)的用法 this.optional(element)是jqu...
jQuery.validate 表单动态验证 实际上jQuery.validate提供了...
自定义验证之这能输入数字(包括小数 负数 ) &lt;script ...