Two RE proposals

David LeBlanc whisper at oz.net
Fri Jul 26 14:42:57 EDT 2002


1. Add a substitution operator - in the example below it's "!<..>"

word = r"\w*"
punct = r"[,.;?]"
wordpunct = re.compile(r"!<word>!<punct>")

The re compiler sees r"\w*[,.;?]"
Trivial example, but for fancier patterns it would be great IMO.
A substitution pass should be done over the substituted text for nesting:

if = r"if"
term = r"something"
num = r"\d*"
op = r"[-+*/]"
factor = r"!<num>\s*!<op>\s*!<num>"
expr = r"!<term>|!<factor>"
if_stmt = re.compile(r"!<if>\s*\(?\s*!<expr>\s*\)?\s*:"
(this is just a muddle to give the idea)

2. Make r"(a|b)*" mean any number of a's or b's. This doesn't work, at least
in some situations with the current re compiler - the "any" op "*" doesn't
seem to span over a parened group. Note that the corresponding group in
groups would have to be a list of strings.

David LeBlanc
Seattle, WA USA





More information about the Python-list mailing list