Parnetheses have special meaning so they must be escaped or specify a character class of 1:
> grep("S\\(.*\\)",c("S(a)","CSP"))
[1] 1
> grep("S[(].*[)]",c("S(a)","CSP"))
[1] 1
On 7/3/07, NOEL Yvonnick <yvonnick.noel_at_free.fr> wrote:
> Hello,
>
> I am trying to find a function name in a string that expresses a
> functional form :
>
> > s = "blabla...S(var)...blabla"
>
> I would like to detect the pattern "S(*)" in s.
>
> I am no guru at regular expressions. Just tried :
>
> > grep("S(.*)",c("S(a)","CSP"))
> [1] 1 2
> >
>
> I expected the pattern to be retrieved only in the first string, so
> obviously this is not correct. Any idea ?
>
> Thank you very much in advance,
>
> Yvonnick Noel, PhD
> U. of Rennes 2
> France
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jul 2007 - 17:32:46 GMT.
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.