[R] how to implement string pattern extraction in R

Daniel Nordlund djnordlund at verizon.net
Mon Aug 23 00:15:47 CEST 2010


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Waverley @ Palo Alto
> Sent: Sunday, August 22, 2010 3:05 PM
> To: r-help
> Subject: [R] how to implement string pattern extraction in R
> 
> Hi,
> 
> In perl, to get a substring matching a particular  pattern can be
> implemented like the following example:
> 
> $x = "AAAA.txt";
> if ($x=~ /(.*?)\.txt/){
>   $prefix = $1;
> }
> 
> So how to do the same thing in R?
> 
> Can someone provide me the code sample?
> 
> Thanks much in advance.
> 
> --
> Waverley @ Palo Alto
> 
Check out the documentation for regexp

?regexp

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA



More information about the R-help mailing list