Grepl issue with brackets or "~"?

The pattern argument for grepl() has to be a "regular expression", not a literal string, and on "regular expressions" parentheses are metacharacters with special meaning, if you want to match a literal parentheses you have to "scape" the metacharacter with two backslashes e.g. aa\\(2014\\s?~\\)

Once again, your question is not related to R but to regular expressions, so please invest a little time learning it, it's not that hard.

1 Like