如何在 stringi 包中使用反向引用?
How to use back reference with stringi package?
在 R 中,我可以使用 \1
来引用捕获组。然而,当使用 stringi 包时,这并没有像预期的那样工作。
library(stringi)
fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\.lst$", "\1"))
[1] "1"
预期输出:hello-you
。
在 the documentation 中我找不到任何关于这个问题的信息。
您需要在替换字符串中使用 </code> 而不是 <code>\1
:
library(stringi)
fileName <- "hello-you.lst"
fileName <- stri_replace_first_regex(fileName, "(.*)\.lst$", "")
[1] "hello-you"
来自doc, stri_*_regex
uses ICU's regular expressions
在 R 中,我可以使用 \1
来引用捕获组。然而,当使用 stringi 包时,这并没有像预期的那样工作。
library(stringi)
fileName <- "hello-you.lst"
(fileName <- stri_replace_first_regex(fileName, "(.*)\.lst$", "\1"))
[1] "1"
预期输出:hello-you
。
在 the documentation 中我找不到任何关于这个问题的信息。
您需要在替换字符串中使用 </code> 而不是 <code>\1
:
library(stringi)
fileName <- "hello-you.lst"
fileName <- stri_replace_first_regex(fileName, "(.*)\.lst$", "")
[1] "hello-you"
来自doc, stri_*_regex
uses ICU's regular expressions