> On 17 Sep 2015, at 23:11, Dimitri Liakhovitski 
> <dimitri.liakhovit...@gmail.com> wrote:
> 
> (x <- c("q10_1", "q10_2", "q10_11", "q12_1", "q12_2", "q13_1", "q13_11"))
> 
> # Which strings start with "q10" or "q12? - WORKS
> x[grep("^q10|q12", x)]
> 
> # Which strings end with "1"? - WORKS
> x[grep("1$", x)]
> 
> # Which strings end with "_1"? - WORKS
> x[grep("\\_1$", x)]
> 
> # Which strings start with "q10" AND contain a "1"? - WORKS
> x[grep("^q10.+1", x)]
> 

For these last to this should “work”

> # Which strings start with "q10" AND end with a "_1"? - DOES NOT WORK
> x[grep("^q10.+\\_1$", x)]
> 

x[grep("^q10.*\\_1$", x)]

> # Which strings start with "q10" or "q12 AND end with "_1"? - WORKS 
> INCORRECTLY
> x[grep("^q10|q12.+\\_1$", x)]
> 

x[grep("^q10|q12.*\\_1$", x)]

It’s the .+ that’s the problem.

Berend

> Thank you!
> Dimitri Liakhovitski
> 
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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