Possible regex match bug (re module)
Randall Hopper
aa8vb at vislab.epa.gov
Tue Apr 6 07:39:17 EDT 1999
Tim Peters:
|Same as in Perl, you're going to have to write a hairier regexp with only
|one interesting group, or give the interesting groups different names and
|sort them out after the match (in an alternation involving named groups, at
|most one will be non-None after a match). Here's a discouraging <wink>
|example of the former approach:
|
|>>> p = re.compile(r"([-=])\1\1(?P<id>((?!\1).)*)\1\1\1").match
I didn't parse your reply carefully enough. The "interesting groups
different names" approach is the one I took, and you're not advocating the
"hairier" form.
I guess what threw me with named groups is that they are identified by
names (like variables) and not position numbers ($1,$2,...), so
context-sensitive assignment seemed to make sense. E.g.:
"if a == b { id = b } else { id = c }"
I'll use different names in the future, and just be thinking numbers. ;-)
Thanks,
Randall
More information about the Python-list
mailing list