How to use back reference with stringi package?

后端 未结 1 1386
一向
一向 2021-01-19 02:24

In R I can use \\\\1 to reference to a capturing group. However, when using the stringi package, this doesn\'t work as expected.

library(stringi         


        
相关标签:
1条回答
  • 2021-01-19 02:40

    You need to use $1 instead of \\1 in the replacement string:

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

    From the doc, stri_*_regex uses ICU's regular expressions

    0 讨论(0)
提交回复
热议问题