[R] grep for asterisks "*"'s
tony.breyal at googlemail.com
Sun Nov 23 10:33:56 CET 2008
Does the following produce what you want mate?
### R START ###
> text <- 'this sentence contains an * (i.e. an astrix).'
> grep('\\*', text)
### R END ###
On 23 Nov, 08:41, Robin Clark <robalexcl... at hotmail.com> wrote:
> I'm trying to determine if a string contains asterisks using the grep
> function. I know that this is slightly difficult because * is a special
> character in regular expressions and needs to be escaped. However, escaping
> the * using \ doesn't work either:
> if(grep("\*", model)>0) #does the model have an interaction
> do something...
> produces the following error message:
> Error in grep("*", model) : invalid regular expression '*'
> In addition: Warning messages:
> 1: '\*' is an unrecognized escape in a character string
> 2: unrecognized escape removed from "\*"
> 3: In grep("*", model) :
> regcomp error: 'Invalid preceding regular expression'
> Execution halted
> Any ideas anyone?
> View this message in context:http://www.nabble.com/grep-for-asterisks-%22*%22%27s-tp20644195p20644...
> Sent from the R help mailing list archive at Nabble.com.
> 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.
More information about the R-help