[R] Regular expression

William Dunlap wdunlap at tibco.com
Tue Jan 15 22:46:07 CET 2013


>> gsub("[',"]", "", "'asd'f")
>Error: unexpected ']' in "gsub("[',"]"
>
>What is the right way to include the 'double quote' in the search field?

The 'search field' is a string and to put a double quote into a double-quote
delimited string you need to escape it with a backslash so it is not
interpreted as the ending quote on the string.
   > gsub("[',\"]", "", "'asd'f")
  [1] "asdf"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Christofer Bogaso
> Sent: Tuesday, January 15, 2013 1:39 PM
> To: r-help
> Subject: [R] Regular expression
> 
> Hello again,
> 
> I am having a problem on Regular expression. Let say I have following code:
> 
> > gsub("[',]", "", "'asd'f")
> [1] "asdf"
> 
> 
> This is perfect. However I am having problem if I include "" (i.e. the
> double quote) in the first argument as the pattern search:
> 
> > gsub("[',"]", "", "'asd'f")
> Error: unexpected ']' in "gsub("[',"]"
> 
> 
> What is the right way to include the 'double quote' in the search field?
> 
> Thanks for your help.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list