shortest match regexp operator anyone?

Andrew Kuchling akuchlin at mems-exchange.org
Wed Jul 11 15:07:39 EDT 2001


Harald Kirsch <kirschh at lionbioscience.com> writes:
> With non-greedy matching, another approximation is '^.*?<A>B', however
> this matches 'xx<A>y<A>B', although it should not.

It sounds like you want something similar to the (?> ...) in Perl 5.6.
Neither SRE nor the current version of PCRE support this, though.
Personally I'd just code it explicitly, as 'index = s.find('<A>') ; if
index != -1: # check for B ...'.  Wordier, but doesn't require regex
arcana.

--amk




More information about the Python-list mailing list