Re: [R] Escaping regular expressions

2009-11-13 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Hadley Wickham > Sent: Friday, November 13, 2009 5:34 AM > To: r-help > Subject: [R] Escaping regular expressions > > Hi all, > > Is there a met

Re: [R] Escaping regular expressions

2009-11-13 Thread Gabor Grothendieck
This is not minimal (it will escape every non-word character) but is short and the needlessly escaped ones should do no harm (though you might want to double check that assumption on a few examples): gsub("(\\W)", "\\1", x) On Fri, Nov 13, 2009 at 8:33 AM, Hadley Wickham wrote: > Hi all, > >

Re: [R] Escaping regular expressions

2009-11-13 Thread Hadley Wickham
I want the user supplied string to be used as a component of a regular expression that I build up from other pieces that need actual regular expressions. Hadley On Fri, Nov 13, 2009 at 7:41 AM, Henrique Dallazuanna wrote: > Try the fixed argument: > > grep(".$^", c("Test.$^", "Test"), fixed = TR

Re: [R] Escaping regular expressions

2009-11-13 Thread Henrique Dallazuanna
Try the fixed argument: grep(".$^", c("Test.$^", "Test"), fixed = TRUE) On Fri, Nov 13, 2009 at 11:33 AM, Hadley Wickham wrote: > Hi all, > > Is there a method for escaping strings to be used regular expressions? >  i.e. if I have a user supplied string that I'd like to use as a fixed > componen

[R] Escaping regular expressions

2009-11-13 Thread Hadley Wickham
Hi all, Is there a method for escaping strings to be used regular expressions? i.e. if I have a user supplied string that I'd like to use as a fixed component is there a method that will turn (e.g.) ".$^" into "\\.\\$\\^" ? Thanks, Hadley -- http://had.co.nz/