在 RI 中可以\\1
用来引用捕获组。但是,当使用 stringi 包时,这不能按预期工作。
library(stringi)
fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1"))
[1] "1"
预期输出:hello-you
.
在文档中,我找不到有关此问题的任何内容。
在 RI 中可以\\1
用来引用捕获组。但是,当使用 stringi 包时,这不能按预期工作。
library(stringi)
fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1"))
[1] "1"
预期输出:hello-you
.
在文档中,我找不到有关此问题的任何内容。
您需要在替换字符串中使用$1
而不是:\\1
library(stringi)
fileName <- "hello-you.lst"
fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "$1")
[1] "hello-you"
从文档中,stri_*_regex
使用ICU 的正则表达式