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 confid...{{dropped:9}}

______________________________________________
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.

Reply via email to