searching backwards in a string

Steve Holden sholden at holdenweb.com
Tue Feb 12 22:12:44 EST 2002


"Paul Rubin" <phr-n2002a at nightsong.com> wrote in message
news:7x8z9y46l1.fsf at ruckus.brouhaha.com...
> "Mark McEahern" <marklists at mceahern.com> writes:
> > That's probably true.  Would you be so kind as to post an example of the
> > input (string, complicated regexp) and output (do you want it to tell
you
> > the starting position from left to right of the first match found
backwards
> > in the string?) you'd expect?
>
> Input string: contents of some random html file
>
> Pattern: match the beginning of an html open or close tag:
>
>   pattern = re.compile("<(/?)(.*?)\b")
>
> How do you search backwards in the html file, starting from location
50000?
>
> I propose adding a "direction flag" to the search function:
>
>    match = pattern.search(text, 50000, -1, direction=-1)
>
> here 50000 and -1 are the starting and ending locations.

Paul, this thread's probably now old enough for you to tell us what the real
problem is! Why exactly do you need to search backwards from the 50,000th
character to find the beginning of an HTML tag?

trust-me-i'm-a-programmer-ly y'rs  - steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Author, Python Web Programming: http://pydish.holdenweb.com/pwp/

"This is Python.  We don't care much about theory, except where it
intersects with useful practice."  Aahz Maruch on c.l.py







More information about the Python-list mailing list