Message-ID: <20090224172310.eabh80cpwwk8o44c@mail.demartines.com>
Date: 2009-02-25T00:23:10Z
From: pierre at demartines.com
Subject: regexp capturing group in R
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 start=20080101 end=20090224"
m <- regexpr("start=(\\d{8}).*end=(\\d{8})", filename, perl=T);
dates = substring(filename, m, m+attr(m,"match.length")-1);
but I get the whole matching substring...
Any idea?
~Pierre