[R] Regular expression problem

Sebastien Bihorel sebastien.bihorel at cognigencorp.com
Tue Sep 15 23:52:22 CEST 2009


Dear R-users,

I am trying to use the grep function to test whether a particular string 
is of the form "n.../mydir/myfile.mytype.myext". Anything between n and 
mytype could vary, and anything after mytype could vary. I tried to 
proceed by steps to build my regular expression... but I do not really 
understand why the last call of the following code do not work.

Any help would be greatly appreciated.

mystr <- "n.../mydir/myfile.mytype.myext"

grep("mytype",mystr)
# returns 1

grep("[.]*mytype",mystr)
# returns 1

grep("n[.]*mytype",mystr)
# returns integer(0)


Sebastien




More information about the R-help mailing list