[R] R Regular Expressions - Metacharacters
    David Winsemius 
    dwinsemius at comcast.net
       
    Tue Feb  5 22:33:51 CET 2013
    
    
  
On Feb 5, 2013, at 9:49 AM, Seth Dickey wrote:
> I thought that I can use metacharacters such as \w to match word characters
> with one backslash.  But for some reason, I need to include two backslashes.
> 
>> grepl(pattern='\w', x="what")
> Error: '\w' is an unrecognized escape in character string starting "\w"
> 
>> grepl(pattern='\\w', x="what")
> [1] TRUE
> 
> I can't find the reason for this on the help pages.  Does anyone know why?
The help page for ?regex says near the top ...
"Any metacharacter with special meaning may be quoted by preceding it with a backslash. The metacharacters in EREs are . \ | ( ) [ { ^ $ * + ?, but note that whether these have a special meaning depends on the context."
> 
> Thanks!
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius
Alameda, CA, USA
    
    
More information about the R-help
mailing list