shortest match regexp operator anyone?

Fredrik Lundh fredrik at pythonware.com
Wed Jul 11 22:17:58 CEST 2001


Harald Kirsch wrote:
> 2) TASK: Find the first '<A>' and match, if it is followed by a 'B'
>    SOLUTION: ???
>
> An approximation for (2) is '^[^<>A]+<A>B', but it does not match
> 'A<A>B', which it should.
>
> With non-greedy matching, another approximation is '^.*?<A>B', however
> this matches 'xx<A>y<A>B', although it should not.

    (?:(?!<A>).)*<A>B

</F>





More information about the Python-list mailing list