More than 9 backreferences in gsub()

后端 未结 6 1615
温柔的废话
温柔的废话 2021-02-20 06:01

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\"
&g         


        
6条回答
  •  一整个雨季
    2021-02-20 06:09

    See Regular Expressions with The R Language:

    You can use the backreferences \1 through \9 in the replacement text to reinsert text matched by a capturing group. There is no replacement text token for the overall match. Place the entire regex in a capturing group and then use \1.

    But with PCRE you should be able to use named groups. So try (?P<name>regex) for groupd naming and (?P=name) as backreference.

提交回复
热议问题