Positive lookahead assertion

tobiah st at tobiah.org
Thu Sep 7 22:18:04 CEST 2006


Sorry, I should have tried harder.  I see that the text
of the match is simply not consumed, so that:

	m = re.search('(?=foo)fo', 'food')

succeeds, while

	m = re.search('(?=fox)fo', 'food')

does not.



tobiah wrote:
> (?=...)
> Positive lookahead assertion. This succeeds if the contained regular 
> expression, represented here by ..., successfully matches at the current 
> location, and fails otherwise. But, once the contained expression has 
> been tried, the matching engine doesn't advance at all; the rest of the 
> pattern is tried right where the assertion started.
> 
> I am unable to wrap my mind around this sentence.  Could
> someone give me an example of how this works, and why
> it would be useful?
> 
> Thanks,
> 
> Toby
> 

-- 
Posted via a free Usenet account from http://www.teranews.com




More information about the Python-list mailing list