shortest match regexp operator anyone?

Richard.Suchenwirth Richard.Suchenwirth at kst.siemens.de
Wed Jul 11 14:11:52 EDT 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.
 
Maybe I don't understand the exact problem, but wouldn't

regexp  {(<A>)B} foo<A>Cbar<A>B -> matched

fulfill task 2?
-- 
Schoene Gruesse/best regards, Richard Suchenwirth - +49-7531-86 2703
Siemens Dematic AG, PA RC D2, Buecklestr.1-5, 78467 Konstanz,Germany
Personal opinions expressed only unless explicitly stated otherwise.



More information about the Python-list mailing list