Reverse abstracting in R (regular expressions)

I am not sure why I cannot get a simple backlink to work in R / RStudio.

grepl('name\1','namename')returns false. grepl('(name)\1','namename')also not good. What am I doing wrong?

Thank!

+4
source share
1 answer

Use a double gap before 1(the regex engine will understand it as a single backslash):

grepl('(name)\\1', 'namename')
## [1] TRUE

This is because:

cat('(name)\\1')
## (name)\1

In your case, \1 == \001means ASCII character code 1.

charToRaw('\1')
## [1] 01
+6
source

Source: https://habr.com/ru/post/1540049/


All Articles