[R] Regular expressions
aleszib at gmail.com
Wed Jan 11 19:12:30 CET 2006
Matching regular expressions
I have the following problem. I would like to find objects in my environment
that have two strings in it. For example, I might want to find objects that
have in their names "MY" and "TARGET". I do not care about the ordering of
these two substrings in the name, neither what is in front, behind or
between them, the only thing important is that both words are present. I
apologize if this is covered in help pages (then I did not understand it by
reading them several times) or it was answered previously (then I did not
Since "ls" with argument pattern essentially uses "grep" (if I am not
mistaken), I have an example for "grep"
text<-c("somethigMYsomthing elseTARGET another thing","MY somthing TARGET
another thing","somethig somthing elseTARGETMY another
thing","somethigMTARGETY another thing")
#I would like to get 1 2 3 and not 4 or actually their names using
#of course, the "pattern" in this case is wrong
I know I can do
However I hope there exists a more elegant way.
Thanks in advance for any suggestions!
More information about the R-help