【发布时间】:2017-11-02 15:33:06
【问题描述】:
一个特定的字符串可以包含我试图匹配的模式的多个实例。例如,如果我的模式是<N(.+?)N>,我的字符串是"My name is <N Timon N> and his name is <N Pumba N>",那么就有两个匹配项。我想用包含要替换匹配项的索引的替换项替换每个匹配项。
所以在我的字符串"My name is <N Timon N> and his name is <N Pumba N>",
我想把字符串改成"My name is [Name #1] and his name is [Name #2]"。
我如何实现这一点,最好使用单个函数?最好使用stringr或stringi的函数?
【问题讨论】:
标签: r string substring stringr stringi