[R] regex scares me
Tony Plate
tplate at acm.org
Mon Aug 28 20:00:52 CEST 2006
I think this does the trick. Note that it is case sensitive.
> x <- c("lad.tab", "xxladyy.tab", "xxyy.tab", "lad.tabx", "LAD.tab",
"lad.TAB")
> grep("lad.*\\.tab$", x, value=T)
[1] "lad.tab" "xxladyy.tab"
>
Jon Minton wrote:
> Hi, apologies if this is too simple but I've been stuck on the following for
> a while:
>
>
>
> I have a vector of strings: filenames with a name before the extension and a
> variety of possible extensions
>
>
>
> I want to select only those files with:
>
> 1) a ".tab" extension
>
> AND
>
> 2) the character sequence "lad" anywhere in the name of the file before the
> extension.
>
>
>
> Surely this won't take long to do, I thought. (But I was wrong.)
>
>
>
> What's the regexp pattern to specify here?
>
>
>
> Thanks,
>
>
>
> Jon Minton
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
More information about the R-help
mailing list