[Python-bugs-list] [ python-Feature Requests-516762 ] have a way to search backwards for re

SourceForge.net noreply at sourceforge.net
Mon Sep 29 15:53:55 EDT 2003


Feature Requests item #516762, was opened at 2002-02-13 03:22
Message generated for change (Comment added) made by phr
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=516762&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: paul rubin (phr)
Assigned to: Gustavo Niemeyer (niemeyer)
Summary: have a way to search backwards for re

Initial Comment:
There doesn't seem to be any reasonable way to search

a string backwards for a regular expression, starting

from a given character position.  I notice that the

underlying C regular expression implemention supports

a direction flag.



I propose adding a direction flag to the search function

on match objects:



r = re.compile(...)

m = re.search(str, startpos=5000, endpos=-1, dir=-1)



would search in str for r, starting at

location 5000 and searching backwards through

location 0 (the beginning of the string).



This is useful in (for example) text editors where

you want to be able to search forwards or backwards,

or if you're parsing an html file and see a </table>

and want to find the matching <table>, etc.



phr



----------------------------------------------------------------------

>Comment By: paul rubin (phr)
Date: 2003-09-29 19:53

Message:
Logged In: YES 
user_id=72053

Another way to do this would be add a direction flag to the 

regexp itself, like re.R (for reverse) if R isn't already in use:



   group  = re.search(pat, str, start, end, re.R)



or something like that.



I continue to want this feature.  It's very handy for writing 

web scrapers, which I do fairly frequently.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-03-27 20:32

Message:
Logged In: YES 
user_id=21627

Moved to feature requests tracker.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=516762&group_id=5470



More information about the Python-bugs-list mailing list