在 R 中我可以使用\\1
引用捕获组。但是,当使用 stringi 包时,这不会按预期工作。
library(stringi)
fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1"))
[1] "1"
预期输出:hello-you
.
In 文档我找不到任何有关这个问题的信息。
你需要使用$1
代替\\1
在替换字符串中:
library(stringi)
fileName <- "hello-you.lst"
fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "$1")
[1] "hello-you"
来自doc, stri_*_regex
uses ICU的正则表达式
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)