Message-ID: <971536df0812020739j606a17a3gb68aa39a8dc06545@mail.gmail.com>
Date: 2008-12-02T15:39:58Z
From: Gabor Grothendieck
Subject: Question to regular expressions
In-Reply-To: <49355510.60502@yahoo.de>
Try this:
> folders <- c("folder1", "f2", "F234562", "12345678", "234567", "912345", "333")
> grep("^[0-9]{6}$", folders, value = TRUE)
[1] "234567" "912345"
On Tue, Dec 2, 2008 at 10:32 AM, Antje <niederlein-rstat at yahoo.de> wrote:
> Hi there,
>
> I know, this question is not directly an R-help question but probably
> someone can give me a hint how to deal with the following problem.
>
> I have a vector with file/folder names and want to filter for all entries
> which have 6 numbers in a row and nothing else.
>
> folders <- c("folder1", "f2", "F234562", "12345678", "234567", "912345",
> "333")
>
> I'd like to get only "234567" and "912345".
> Can anybody help me creating a regex for this???
>
> For example this regex:
>
> regexpr("[^:digit:$]{6}", folders)
>
> would match "F234562", "12345678", "234567", "912345"
>
>
> Antje
>
> ______________________________________________
> 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.
>