Re: [R] regexp capturing group in R

2009-02-24 Thread Christos Hatzis
es [1] "20080101" "20090224" -Christos > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of > pie...@demartines.com > Sent: Tuesday, February 24, 2009 7:23 PM > To: r-help@r-project.org > Subj

Re: [R] regexp capturing group in R

2009-02-24 Thread Gabor Grothendieck
Try this: library(gsubfn) strapply("blah blah start=20080101 end=20090224", "start=(\\d{8}) end=(\\d{8})", c, perl = TRUE)[[1]] or perhaps just: strapply("blah blah start=20080101 end=20090224", "\\d{8}", perl = TRUE)[[1]] On Tue, Feb 24, 2009 at 7:23 PM, wrote: > Hello, > > Newbie question

Re: [R] regexp capturing group in R

2009-02-24 Thread jim holtman
> txt <- "blah blah start=20080101 end=20090224" > nums <- sub(".*start=(\\d+).*end=(\\d+).*", "\\1 \\2", txt, perl=TRUE) > nums <- strsplit(sub(".*start=(\\d+).*end=(\\d+).*", "\\1 \\2", txt, > perl=TRUE), ' ') > nums [[1]] [1] "20080101" "20090224" On Tue, Feb 24, 2009 at 7:23 PM, wrote: >

[R] regexp capturing group in R

2009-02-24 Thread pierre
Hello, Newbie question: how do you capture groups in a regexp in R? Let's say I have txt="blah blah start=20080101 end=20090224". I'd like to get the two dates start and end. In Perl, one would say: my ($start,$end) = ($txt =~ /start=(\d{8}).*end=(\d{8})/); I've tried: txt <- "blah blah star