"$" 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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Data Analytics Corp. > Sent: Monday, January 07, 2013 1:22 PM > To: r-help@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 > w...@dataanalyticscorp.com > www.dataanalyticscorp.com > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.