[R] ? Exact pattern matching in GREP ?

Hedderik van Rijn hedderik at van-rijn.org
Fri Sep 27 17:04:59 CEST 2002


> How is exact pattern matching achieved in GREP (and GREPlike) 
> functions ?

 From ?grep:

      The regular expressions used are those specified by POSIX 1003.2,
      either extended or basic, depending on the value of the `extended'
      argument.

On how to specify the expressions, see "man re_format" or Google for 
"POSIX 1003.2".

> # Want: listing of all object names that end in *.lm
>> objects(pattern="*.lm",pos=1)

 > grep("\\.lm$",c("test1.lm","test.lm.txt","testlm"))
[1] 1

> #  Want:  position of string "4jan2002" in vector
>> date.index <- grep("4jan2002", my.dates)
> # .... but get:
>> my.dates[date.index]
> [1]  "4jan2002"  "24jan2002"   "14jan2002"

 > grep("^4jan2002$",c("4jan2002","24jan2002","14jan2002b","4jan2002b"))
[1] 1

  - Hedderik.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list