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.
>> 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.
HI,
vec1<-"'asd'f"
?vec2<-'"asd"f'
?gsub("[\"]","",vec2)
#[1] "asdf"
?gsub("[']","",vec1)
#[1] "asdf"
A.K.
----- Original Message -----
From: Christofer Bogaso <bogaso.christofer at gmail.com>
To: r-help <r-help at r-project.org>
Cc:
Sent: Tuesday, January 15, 2013 4:38 PM
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.