加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 22:54:28 所属栏目:百科 来源:网络整理
导读:如何使用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"
如何使用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)作为反向引用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读