[R] Perl-style regexes and capturing results

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu May 4 16:00:27 CEST 2006


On Thu, 4 May 2006, Sean Davis wrote:

> Just a quick question....
>
> In perl, I can capture parts of a regex like /(\w)\/(\d)/ to get back $1 and
> $2 containing the parts of the regex in parentheses.  Is there a parallel in
> R?

Yes.  See ?gsub and especially the examples.  This is not specific to 
Perl, and \1 and \2 are more commonly used, including in R.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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, UK                Fax:  +44 1865 272595




More information about the R-help mailing list