[R] pattern matching
William Dunlap
wdunlap at tibco.com
Mon Jan 7 22:45:48 CET 2013
"$" has a special meaning (end-of-string) in regular expressions, so you can either escape it with "\\" or not use regular expressions in regexpr():
> regexpr("\\$", "x$Expensive")
[1] 2
attr(,"match.length")
[1] 1
attr(,"useBytes")
[1] TRUE
> regexpr("$", "x$Expensive", fixed=TRUE)
[1] 2
attr(,"match.length")
[1] 1
attr(,"useBytes")
[1] TRUE
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 Data Analytics Corp.
> Sent: Monday, January 07, 2013 1:22 PM
> To: r-help at R-project.org
> Subject: [R] pattern matching
>
> Hi,
>
> I have a simple question. Suppose I have a string "x$Expensive". I want
> to find the position of the $ in this string; i.e., I want a function
> that returns 2. I tried grep, regexpr, etc with no luck, unless I'm
> just using them incorrectly. Any suggestions?
>
> Thanks,
>
> Walt
>
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> walt at dataanalyticscorp.com
> www.dataanalyticscorp.com
>
> ______________________________________________
> 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