5

在 RI 中可以\\1用来引用捕获组。但是,当使用 stringi 包时,这不能按预期工作。

library(stringi)

fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1"))

[1] "1"

预期输出:hello-you.

文档中,我找不到有关此问题的任何内容。

4

1 回答 1

5

您需要在替换字符串中使用$1而不是:\\1

library(stringi)

fileName <- "hello-you.lst"
fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "$1")

[1] "hello-you"

文档中,stri_*_regex使用ICU 的正则表达式

于 2015-08-25T15:32:00.610 回答