Match First Sequence in Regular Expression?

Christos Georgiou tzot at sil-tec.gr
Thu Jan 26 17:52:40 CET 2006


On Thu, 26 Jan 2006 16:41:08 GMT, rumours say that "Roger L. Cauvin"
<roger at deadspam.com> might have written:

>Good suggestion.  Here are some "test cases":
>
>"xyz123aaabbab" accept
>"xyz123aabbaab" reject
>"xayz123aaabab" accept
>"xaaayz123abab" reject
>"xaaayz123aaabab" accept

Applying my last regex to your test cases:

>>> r.match("xyz123aaabbab")
<_sre.SRE_Match object at 0x00B47F60>
>>> r.match("xyz123aabbaab")
>>> r.match("xayz123aaabab")
<_sre.SRE_Match object at 0x00B50020>
>>> r.match("xaaayz123abab")
>>> r.match("xaaayz123aaabab")
<_sre.SRE_Match object at 0x00B47F60>
>>> print r.pattern
^(?:.*?[^a])?(a{3})(?:b[ab]*)?$

You should also remember to check the (match_object).start(1) to verify that
it matches the "aaa" you want.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians



More information about the Python-list mailing list