searching backwards in a string

Paul Rubin phr-n2002a at nightsong.com
Tue Feb 12 16:04:27 EST 2002


"Mark McEahern" <marklists at mceahern.com> writes:
> > I have a string and want to search backwards for a regexp, starting at
> > a given index, like if you search backwards in a text editor.  Is
> > there a way to do that with re?  The docs aren't clear about what's
> > supposed to happen if the ending position to the pat.search method is
> > less than the starting position, but I tried it and it doesn't seem
> > to do what I want.  Any advice appreciated--thanks.
> 
> Short answer:  Reverse the string first.

Thanks but I don't think that solution works if the pattern being
searched for is a complicated regexp.  Even if the pattern is a simple
string, it has to be reversed too.



More information about the Python-list mailing list