Skip to content
Prev 316910 / 398506 Next

R Regular Expressions - Metacharacters

On 05/02/2013 12:49 PM, Seth Dickey wrote:
grepl wants a string containing a single backslash.  R uses the 
backslash as an escape character, so you need to double it in your 
source, so the string ends up containing just one.

"\w" is interpreted by R as an escaped w, which doesn't make sense.

"\\w" is interpreted by R as a backslash followed by a w, and then the 
\w is interpreted by grepl the way you want.

Duncan Murdoch