如何在stringi包中使用反向引用? [英] How to use back reference with stringi package?
本文介绍了如何在stringi包中使用反向引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在R中,我可以使用\\1
引用捕获组.但是,在使用stringi软件包时,此操作无法按预期进行.
In R I can use \\1
to reference to a capturing group. However, when using the stringi package, this doesn't work as expected.
library(stringi)
fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1"))
[1] "1"
预期输出:hello-you
.
在文档我找不到与此问题有关的任何东西.
In the documentation I couldn't find anything concerning this problem.
推荐答案
您需要在替换字符串中使用$1
而不是\\1
:
You need to use $1
instead of \\1
in the replacement string:
library(stringi)
fileName <- "hello-you.lst"
fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "$1")
[1] "hello-you"
在 doc 中,stri_*_regex
使用 ICU的正则表达式
这篇关于如何在stringi包中使用反向引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文