An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090109/4526c014/attachment-0001.pl>
grep : escape "*"
7 messages · Henrique Dallazuanna, Duncan Murdoch, Gábor Csárdi +3 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090109/79260fc1/attachment-0001.pl>
On 1/9/2009 10:38 AM, David Hajage wrote:
Dear R useRs, Sorry for this foolish question, but I can't find how to escape the * character when using grep :
You use a backslash to escape the *. Unfortunately, to enter a backslash in an R string, you need to escape it. So the pattern is "\\*". Duncan Murdoch
grep("-", c("/3", "2*3", "4-4"))
[1] 3
grep("/", c("/3", "2*3", "4-4"))
[1] 1
grep("*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
expression r?guli?re incorrecte '*'
De plus : Warning message:
In grep("*", c("/3", "2*3", "4-4")) :
erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'
grep("\*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
expression r?guli?re incorrecte '*'
De plus : Warning messages:
1: '\*' est un code escape non reconnu dans une cha?ne de caract?res
2: code escape non reconnu ?limin? de "\*"
3: In grep("*", c("/3", "2*3", "4-4")) :
erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'
Best regards,
david
[[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.
* must be escaped for grep with \ and \ must be escaped for R itself
with another \, so you need
grep("\\*", c("/3", "2*3", "4-4"))
Gabor
2009/1/9 David Hajage <dhajage.r at gmail.com>:
Dear R useRs, Sorry for this foolish question, but I can't find how to escape the * character when using grep :
grep("-", c("/3", "2*3", "4-4"))
[1] 3
grep("/", c("/3", "2*3", "4-4"))
[1] 1
grep("*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
expression r?guli?re incorrecte '*'
De plus : Warning message:
In grep("*", c("/3", "2*3", "4-4")) :
erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'
grep("\*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
expression r?guli?re incorrecte '*'
De plus : Warning messages:
1: '\*' est un code escape non reconnu dans une cha?ne de caract?res
2: code escape non reconnu ?limin? de "\*"
3: In grep("*", c("/3", "2*3", "4-4")) :
erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'
Best regards,
david
[[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.
Gabor Csardi <Gabor.Csardi at unil.ch> UNIL DGM
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090109/42da3269/attachment-0001.pl>
Use fixed = TRUE argument to grep. 2009/1/9 David Hajage <dhajage.r at gmail.com>:
Dear R useRs, Sorry for this foolish question, but I can't find how to escape the * character when using grep :
grep("-", c("/3", "2*3", "4-4"))
[1] 3
grep("/", c("/3", "2*3", "4-4"))
[1] 1
grep("*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
expression r?guli?re incorrecte '*'
De plus : Warning message:
In grep("*", c("/3", "2*3", "4-4")) :
erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'
grep("\*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
expression r?guli?re incorrecte '*'
De plus : Warning messages:
1: '\*' est un code escape non reconnu dans une cha?ne de caract?res
2: code escape non reconnu ?limin? de "\*"
3: In grep("*", c("/3", "2*3", "4-4")) :
erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'
Best regards,
david
[[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.
Hi there, you probably want something like:
# R
grep("\\*", c("/3", "2*3", "4-4"))
hope that helps a little,
Tony Breyal
On 9 Jan, 15:38, "David Hajage" <dhajag... at gmail.com> wrote:
Dear R useRs, Sorry for this foolish question, but I can't find how to escape the * character when using grep :
grep("-", c("/3", "2*3", "4-4"))
[1] 3
grep("/", c("/3", "2*3", "4-4"))
[1] 1
grep("*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
? expression r?guli?re incorrecte '*'
De plus : Warning message:
In grep("*", c("/3", "2*3", "4-4")) :
? erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'> grep("\*", c("/3", "2*3", "4-4"))
Erreur dans grep("*", c("/3", "2*3", "4-4")) :
? expression r?guli?re incorrecte '*'
De plus : Warning messages:
1: '\*' est un code escape non reconnu dans une cha?ne de caract?res
2: code escape non reconnu ?limin? de "\*"
3: In grep("*", c("/3", "2*3", "4-4")) :
? erreur rgcomp : 'Expression r?guli?re pr?c?dente incorrecte'
Best regards,
david
? ? ? ? [[alternative HTML version deleted]]
______________________________________________ R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.