J
James Collier
Is it possible to capture the results of repeating group matches in the
python regular expression module?
To illustrate, what I want is:
instead of
("aW", "eX", "fY")
.... which captures only the last match from the second group.
Of course, one option is to break out the substring containing the
repeating group and then use split() or findall() within the substring,
but, but, but ... I'd like to do it in one hit if possible.
I believe someone has raised a similar question before, but I can't find
a definitive answer. It may be so stunningly obvious that nobody ever
bothers to answer - if so, could some kind soul please humour me and at
least point me to what I'm not seeing in the Fine Manual.
Thanks,
James.
python regular expression module?
To illustrate, what I want is:
('aW','bX','cX','dX','eX','fY')>>> re1 = re.compile("([a-z]W)([a-z]X)+([a-z]Y)");
>>> mo1 = re.match("aWbXcXdXeXfY");
>>> print mo1.groupsButNotAsWeKnowIt()
instead of
("aW", "eX", "fY")
.... which captures only the last match from the second group.
Of course, one option is to break out the substring containing the
repeating group and then use split() or findall() within the substring,
but, but, but ... I'd like to do it in one hit if possible.
I believe someone has raised a similar question before, but I can't find
a definitive answer. It may be so stunningly obvious that nobody ever
bothers to answer - if so, could some kind soul please humour me and at
least point me to what I'm not seeing in the Fine Manual.
Thanks,
James.