Waverley
2008-Oct-09 00:20 UTC
[R] question of R to do perl matching and matched string extraction
Hi,
I want to extract some of the substring via pattern recognition. But
I don't know how to do it in R.
In perl:
my $url = "/pages-cell.net/deepan/sony/";
if($url =~ m/\/(.*)\//g)
{
my @result = $1;
return @result;
}
How does the same work in R?
Thanks much in advance
--
Waverley @ Palo Alto
jim holtman
2008-Oct-09 02:02 UTC
[R] question of R to do perl matching and matched string extraction
Is this what you want:> x <- "/pages-cell.net/deepan/sony/" > z <- gsub("/(.*)/", "\\1", x) > > z[1] "pages-cell.net/deepan/sony" On Wed, Oct 8, 2008 at 8:20 PM, Waverley <waverley.paloalto at gmail.com> wrote:> Hi, > > I want to extract some of the substring via pattern recognition. But > I don't know how to do it in R. > > In perl: > my $url = "/pages-cell.net/deepan/sony/"; > > if($url =~ m/\/(.*)\//g) > { > my @result = $1; > return @result; > } > > > How does the same work in R? > > Thanks much in advance > -- > Waverley @ Palo Alto > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?