try: > grep("n.*mytype",mystr) [1] 1
with the [.] it is a class with a period. '.*' match zero, or more, characters. On Tue, Sep 15, 2009 at 5:52 PM, Sebastien Bihorel <sebastien.biho...@cognigencorp.com> wrote: > 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 > > ______________________________________________ > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ 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.