2
string_1 = "[1] \"  .. ..$ : chr [1, 1] \\\"DM_4CRSOL\\\"\""

How to extract 'DM_4CRSOL' from string_1 using regex in R?

Thanks in advance.

User
  • 378
  • 1
  • 3
  • 16

2 Answers2

3

I like to expand on romles answer:

#install.packages("stringi")
library(stringi)
string_1 = "[1] \"  .. ..$ : chr [1, 1] \\\"DM_4CRSOL\\\"\""
stri_extract(string_1, regex = '(?<=\\\\").*(?=\\\\")')

gives

[1] "DM_4CRSOL"
RLesur
  • 5,810
  • 1
  • 18
  • 53
wp78de
  • 18,207
  • 7
  • 43
  • 71
2

This does the task:
stringi::stri_extract(string_1, regex = '(?<=\\\\").*(?=\\\\")')

RLesur
  • 5,810
  • 1
  • 18
  • 53