RE question

Mike Fletcher mfletch at tpresence.com
Tue Apr 18 15:40:41 CEST 2000


Your regex matches any letter of [abc] at least once, stores that as the
group result, then goes back and tries again.  The last result the group
gets is c...

[abc] -> a
() -> store a
+ -> repeat group
[abc] -> b
() -> store b
+ -> repeat group
[abc] -> c
() -> store c
+ -> repeat group
[abc] -> stop
() -> stop
return, with c as result for group 1

Re's don't allow for storing multiple group match results for the same
group.  For that, get yourself a parsing system :) .

try:
	([abc]+) -> abc
except MikeyMissingPoint:
	shake head in amazement at him

HTH,
Mike


-----Original Message-----
From: Benyang Tang [mailto:btang at pacific.jpl.nasa.gov]
Sent: Monday, April 17, 2000 7:24 PM
To: python-list at python.org
Subject: RE question




>>> m = re.match("([abc])+", "abc"); m.group(1)
'c'

Why is it 'c', instead of 'a'?
-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list