How can I access all matches with groupings (i.e. label
) using gregexpr()
in R?
s <- "aaa123bbb345ccc"
p <- "(?<label>\\d+)"
m <- gregexpr(p, s, perl = TRUE)
I am interested in printing the matches in m but referencing the group name <label1>
. This can be easily done in C# but I'm struggling in R and I cannot figure out how to do this from the CRAN docs.
Edit: C# code below requested by G Grothendieck:
string s = "aaa123bbb345ccc";
string p = @"(?<label>\d+)";
Regex r = new Regex(p);
Match m = r.Match(s);
if (m.Success)
{
Console.WriteLine(m.Groups["label"].Value);
}