shortest match regexp operator anyone?

Donal K. Fellows fellowsd at cs.man.ac.uk
Thu Jul 12 05:24:46 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.

This isn't purely a regexp, but it is a one-liner:

  if {[regexp -indices {<A>(B)?} $string matched gotB]&&[lindex $gotB 0]+1} {
     #....
  }

Donal.
-- 
Donal K. Fellows    http://www.cs.man.ac.uk/~fellowsd/    fellowsd at cs.man.ac.uk
-- Actually, come to think of it, I don't think your opponent, your audience,
   or the metropolitan Tokyo area would be in much better shape.
                                        -- Jeff Huo <jeff at starfall.com.nospam>



More information about the Python-list mailing list