a RegEx puzzle

Peter Otten __peter__ at web.de
Fri Mar 11 17:54:15 CET 2005

Charles Hartman wrote:

> pat = sre.compile('(x[x/])+')
> (longest, startlongest) = max([(fnd.end()-fnd.start(), fnd.start()) for
> i in range(len(marks))
> for fnd in pat.finditer(marks,i)])

If I'm understanding that correctly, the only way for you to get different
best matches are at offsets 0 and 1; offset 2 will yield the same matches
as 0, with the possibility of excluding the first two characters -- i. e.
any different matches should be guaranteed to be shorter. Therefore

... for i in range(2) ...

instead of

... for i in range(len(marks)) ...

should be sufficient.


More information about the Python-list mailing list