search (match) backward

Greg Ewing greg.ewing at compaq.com
Wed Oct 27 06:09:23 EDT 1999


mehta at mama.indstate.edu wrote:
> 
> is there facility to get the match or search backward providing a start
> and end position?

There's nothing built-in as far as I know.

My first thought is to reverse both the string you're searching
and the thing you're searching for and search forwards.

If you're searching for a fixed string, this is straightforward.
If you're searching for an RE, it might be trickier.

This raises the interesting question of whether there is an
algorithm for reversing an RE (i.e. find an RE which matches
the reverse of the strings that the original RE matches).
Can it even be done in general? My intuition says yes, but
I can't think of a proof off the top of my head.

Greg




More information about the Python-list mailing list