"We are working on some minor configuration/security issues which may result in odd behavior over the next 24-48 hours." -- notice on a BBS
On Jan 18, 2005, at 5:08 PM, Nicholas Riley wrote:
On Tue, Jan 18, 2005 at 04:40:54PM -0500, Charles Hartman wrote:find 'abca' in string 'abcabca'
Every *single* RE I can think of misses the second instance (beginning in position 3) in the first example, because it's eaten the beginning of it in finding the first instance.
Lookahead will do this one, e.g.:
In [39]: [m.span() for m in re.finditer(r'(?=abca)', 'abcabca')] Out[39]: [(0, 0), (3, 3)]
find longest '(a[ab])+' in string 'baabaaabba'
I don't think even Perl regexps can do the second one, but I might be wrong. Neither greedy or non-greedy quantifiers will compare match length. You could get a list of all matches and pick the longest one yourself.
--
Nicholas Riley <[EMAIL PROTECTED]> | <http://www.uiuc.edu/ph/www/njriley>
_______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig