Difficulty Finding Python Developers

Bill Anderson banderson at hp.com
Mon May 3 05:53:13 EDT 2004


On Thu, 15 Apr 2004 17:37:47 -0700, Paul Rubin wrote:


> 1) Python's regexp module has no way to search backwards in a string
>    for a regexp, i.e. find the last occurence of the regexp before
>    location x.

Maybe I don't get it but ... use findall. It takes an end position, and
the last one in the list is the last one before location x.

foo = re.compile(regex)
foo.findall(stringtosearchon,0,50)[-1]

returns the last occurence of the regex prior to location 50.

Granted this took about 5 minutes to figure out, but it seems to solve the
problem well enough.

What am I missing?



More information about the Python-list mailing list