标签: regex r
如何在R中引用匹配的字符串(或捕获的组)以便附加在sub()中。例如,我会在sed中这样做,以便为匹配附加'd'
sub()
sed
'd'
echo "66xx" | sed 's/[0-9][0-9]/&d/g' 66dxx
答案 0 :(得分:7)
> sub("([0-9][0-9])(.*)","\\1d\\2", "66xx") [1] "66dxx"