Thanks Jim and Rolf, grep("n.*mytype",mystr) will do.
I thought that * only applies on group of characters defined in a [] sequence. Would you be aware of any documentation/tutorial that would give slightly more detail and examples that the ?regexp? Also, would you be aware of any (online) tool to test "R-style" regular expression against some text or strings? > > On 16/09/2009, at 9:58 AM, jim holtman wrote: > >> try: >> >>> grep("n.*mytype",mystr) >> [1] 1 >> >> >> with the [.] it is a class with a period. '.*' match zero, or >> more, characters. > > Perhaps the OP wants > > grep("n[.].*mytype",mystr) > > to insist that ``mystr'' contain the string ``n.'' (literal ``.'') > somewhere before the string ``mytype''. > > cheers, > > Rolf Turner >> >> 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. > > > ###################################################################### > Attention: > This e-mail message is privileged and confidential. If you are not the > intended recipient please delete the message and notify the sender. > Any views or opinions presented are solely those of the author. > > This e-mail has been scanned and cleared by MailMarshal > www.marshalsoftware.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.