Negative Lookahead Problem
Terry Reedy
tjreedy at udel.edu
Thu Dec 5 17:02:58 EST 2002
n Thu, Dec 05, 2002 at 12:11:54PM +0000, Roger Day wrote:
> import re
>
> path = ["/users/dibbl","users/rsrc"]
> print "expect 1st element to be selected"
> m = re.compile(".*(?!rsrc$)")
> for p in path:
> kk = m.match( p )
> if kk:
> print p
> > expect 1st element to be selected
> > /users/dibbl
> > users/rsrc
> > In the first test case, the negative-lookahead "fails"
I suspect its because .* matches (gobbles up) the whole string,
which is then not followed by whatever. I think the suggestion
to use .endswith() is a good one.
TJR
More information about the Python-list
mailing list