[R] RegExpr: Help match quote inside a set

Martin Møller Skarbiniks Pedersen tr@xp|@yer @end|ng |rom gm@||@com
Fri Feb 21 13:17:59 CET 2020


  I am trying to understand the different functions for working with
regular expression in R.
  However I get a strange result for one of experiments, which I need
help to understand.

First: I search for any of the characters .,;"- in the book emma
> length(grep("[.,;\"-]",janeaustenr::emma))
[1] 13110
And that is probably correct.

Second: I try to add ' to the set to search for:
> length(grep("[.,;\"-']",janeaustenr::emma))
[1] 12816

No warning or errors but fewer hits? Why?

Third: I try quoting the ' and probably now gets the correct result.
> length(grep("[.,;\"-\\']",janeaustenr::emma))
[1] 13433

But still what does grep("[.,;\"-']", janeaustenr::emma) exactly?


sorry for the html. It is not possible to remove it complete in gmail.

More information about the R-help mailing list