gpt4 book ai didi

r - 如何在stringi包中使用反向引用?

转载 作者:行者123 更新时间:2023-12-04 09:47:39 25 4
gpt4 key购买 nike

在 R 我可以使用 \\1引用捕获组。但是,当使用 stringi 包时,这不会按预期工作。

library(stringi)

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

[1] "1"

预期输出: hello-you .

the documentation我找不到有关此问题的任何信息。

最佳答案

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

library(stringi)

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

[1] "hello-you"

来自 doc , stri_*_regex用途 ICU's regular expressions

关于r - 如何在stringi包中使用反向引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32207958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com