From: Stavros Macrakis <macrakis_at_alum.mit.edu>

Date: Sat, 29 Nov 2008 15:55:38 -0500

R-help_at_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. Received on Sat 29 Nov 2008 - 20:57:31 GMT

Date: Sat, 29 Nov 2008 15:55:38 -0500

Hmm, this brings up an interesting question. What if the string I'm looking for contains escape characters? For example, grep( paste( "^", "(ab)" ), c("ab","(ab)") ) => c(1), not c(2).

On Sat, Nov 29, 2008 at 7:12 AM, Gabor Grothendieck <ggrothendieck_at_gmail.com

*> wrote:
*

> > a <- 2:3

*> > b <- c("aaa 2 aaa", "2 aaa", "3 aaa", "aaa 3 aaa")
**> > re <- paste("^(", paste(a, collapse = "|"), ")", sep = "")
**> > grep(re, b, value = TRUE)
**> [1] "2 aaa" "3 aaa"
**>
*

[[alternative HTML version deleted]]

R-help_at_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. Received on Sat 29 Nov 2008 - 20:57:31 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Sun 30 Nov 2008 - 00:30:27 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*