[R] Retrieve regular expression groups
OKB (not okblacke)
brenbarn at brenbarn.net
Mon May 3 00:03:28 CEST 2010
I'm trying to figure out how to get the text captured by capturing
groups out of a regex match. For instance, let's say I have the pattern
"foo ([^ ]+)" and I match it against the string "This is a foo sentence
I am reading." The group in the pattern will match the word "sentence"
in the target string. How can I get access to this matched group? All
I can seem to get the various grep/gsub functions to do is return or
modify the entire target string. Isn't there a way to extract ONLY the
text from a particular group or groups?
Thanks,
--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
More information about the R-help
mailing list