Skip to content
Back to formatted view

Raw Message

Message-ID: <C698D707214E6F4AB39AB7096C3DE5A57513B9@phost015.EVAFUNDS.intermedia.net>
Date: 2004-11-19T01:55:44Z
From: Vadim Ogranovich
Subject: how to get to interesting part of pattern match

Hi,

I am looking for a way to extract an "interesting" part of the match to
a regular expression. For example the pattern "[./](*.)" matches a
substring that begins with either "." or "/" followed by anything. I am
interested in this "anything" w/o the "." or "/" prefix. If say I match
the pattern against "abc/foo" I want to get "foo", not "/foo". In Perl
one can simply wrap the "interesting" part in () and get it out of the
match. Is it possible to do a similar thing in R?

There seems to be a way to refer to the match, see below, but I couldn't
figure out how to make gsub return it.
> gsub("[./](*.)", "\\1", "abc/foo")
[1] "abcfoo"


Thanks,
Vadim