[R] Question to regular expressions
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@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.
Re: [R] Question to regular expressions
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 [EMAIL PROTECTED] 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@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. __ R-help@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.
Re: [R] Question to regular expressions
Hi Gabor, it works! Thank you very much! But I still don't understand the difference between [0-9] and [:digit:]... Ciao, Antje Gabor Grothendieck schrieb: 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 [EMAIL PROTECTED] 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@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. __ R-help@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.
Re: [R] Question to regular expressions
Try this: ^[[:digit:]]{6}$ On Tue, Dec 2, 2008 at 10:48 AM, Antje [EMAIL PROTECTED] wrote: Hi Gabor, it works! Thank you very much! But I still don't understand the difference between [0-9] and [:digit:]... Ciao, Antje Gabor Grothendieck schrieb: 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 [EMAIL PROTECTED] 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@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. __ R-help@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.
Re: [R] Question to regular expressions
On Tue, Dec 2, 2008 at 9:48 AM, Antje [EMAIL PROTECTED] wrote: Hi Gabor, it works! Thank you very much! But I still don't understand the difference between [0-9] and [:digit:]... You might find this site helpful: http://regexp.resource.googlepages.com/analyzer.html Copy in your attempt and Gabor's correction to see the difference more clearly. Hadley -- http://had.co.nz/ __ R-help@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.
Re: [R] Question to regular expressions
Antje wrote: Hi Gabor, it works! Thank you very much! But I still don't understand the difference between [0-9] and [:digit:]... If all else fails, read the help, here ?regex. Both [0-9] and [[:digit:]] are character classes of digits, but the first contains only arabic numerals. In some locales the second may contain other numerals (e.g. Japanese has other characters representing digits): however I believe that in the current R implementations that no other numerals are included in any locale. Ciao, Antje Gabor Grothendieck schrieb: 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 [EMAIL PROTECTED] 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@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. __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] Question to regular expressions
Thanks a lot again to all of you!!! Antje Antje schrieb: Hi Gabor, it works! Thank you very much! But I still don't understand the difference between [0-9] and [:digit:]... Ciao, Antje Gabor Grothendieck schrieb: 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 [EMAIL PROTECTED] 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@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. __ R-help@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. __ R-help@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.