Bra*_*roy 5 backreference r stringi
在RI中可以\\1用来引用捕获组。但是,在使用stringi软件包时,此操作无法按预期工作。
library(stringi)
fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1"))
[1] "1"
Run Code Online (Sandbox Code Playgroud)
预期输出:hello-you。
在文档中,我找不到与该问题有关的任何内容。
您需要使用$1而不是\\1替换字符串:
library(stringi)
fileName <- "hello-you.lst"
fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "$1")
[1] "hello-you"
Run Code Online (Sandbox Code Playgroud)