Complete word matching using grepl in R

“\<” is another escape sequence for the beginning of a word, and “\>” is the end.
In R strings you need to double the backslashes, so:

> grepl("\\<is\\>", c("this", "who is it?", "is it?", "it is!", "iso"))
[1] FALSE  TRUE  TRUE  TRUE FALSE

Note that this matches “is!” but not “iso”.

Leave a Comment