mbsheikh
mbsheikh

Reputation: 2521

R: Regular expression is invalid in this locale

I have the following regular expression in an R script:

grepl("\xe9", "MY TEXT", fixed = FALSE, ignore.case = TRUE, perl = FALSE)

I get the following error:

Error in grepl("\xe9", "MY TEXT", fixed = FALSE, ignore.case = TRUE,  : 
regular expression is invalid in this locale

"\xe9" is unicode representation of "é" and is read as-is from a file.

How can I fix this? Additionally, is there a useful resource on locales w.r.t regular expression in R?

Upvotes: 2

Views: 1936

Answers (1)

IRTFM
IRTFM

Reputation: 263411

I don't know why @joran didn't just post this as an answer:

grepl("\\xe9", c("MY TEXT", "é"), fixed = FALSE, ignore.case = TRUE, perl = FALSE)
#[1] FALSE  TRUE

Upvotes: 4

Related Questions