Is it possible to create a regular expression with a variable number of groups?
After running this for instance...
Pattern p = Pattern.compile("ab([cd])*ef");
Matcher m = p.matcher("abcddcef");
m.matches();
... I would like to have something like
m.group(1)
="c"
m.group(2)
="d"
m.group(3)
="d"
m.group(4)
="c"
.
(Background: I'm parsing some lines of data, and one of the "fields" is repeating. I would like to avoid a matcher.find
loop for these fields.)
As pointed out by @Tim Pietzcker in the comments, perl6 and .NET have this feature.