Escape character for char location in line: R lang

I am trying to get location \or /in line. Below is the code I'm trying to do:

x <- "<span id=\"ref_12590587_l\">6,803.61</span>_l>"
gregexpr("\\\", x)
which(strsplit(x, "")[[1]]=="\")

My problem is that when I try to execute these codes in Rstudio, I get an invitation to continue, the REPL request becomes +. These codes work for other characters.

Why do I get a continue prompt, although \quoted in quotation marks?

Edit: fixed line after comment.

+4
source share
2 answers

You need to add another slash (as stated in the comments of stribizhev). So you are looking

gregexpr("\\\\", x)

, \, . , \\ 1 . 3, !

. :

gregexpr("\"", 'hello, "hello"')

.

+1

:

  • x , , .
  • gregexpr("\\\", x) , , , "" .
  • \ gregexpr 4 \\\\, gregexpr . "\" , . gregexpr , \ escape-, \n. , R, .

,

gregexpr("\\\\", x) 

,

gregexpr("\\\\|/", x)

.

IDEONE

+1

All Articles