Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Would like regexps to accept a -backward flag for searching

Closed / Wont Fix219264ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 19 years ago
Descriptionplain2000-10-26 05:09:33
OriginalBugID: 1059 RFE
Version: 8.1b1
SubmitDate: '1999-01-15'
LastModified: '1999-08-04'
Severity: LOW
Status: UnAssn
Submitter: pat
ChangedBy: stanton
OS: Windows NT
OSVersion: 4.0; I also use MacOS 8.5.1
Machine: X86
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name:
vince darley

Extensions:
none

DesiredBehavior:
regexps only find the first match in the given text; it would be very useful to be able to have a '-backwards' flag which started searching from the end of the given string.

As well as being a useful feature, this addition would speed up backwards searches in the Text widget, which currently pretends to search backwards by repeating forward searches until it can't find another forward match.

In Tcl 8.0 it was reasonably easy to write one's own 'regexec' function which matched backwards instead of forwards (using the built in regexp procedures).  However the new regexp code in Tcl 8.1 is so complex it's not clear how to do that any more (although I love the new regexp features).  Probably it still isn't conceptually that difficult for someone who actually understands that code ;-)
dkfplain2000-11-10 17:16:00
You could instead (especially on shorter search spaces) get regexp to return the list of all the indices for matches which it found up to the point you are interested (selecting that part of the string with [string range] of course.)  Not perfect by any means, but may help some people.

Or you could reverse the string, but this is yet another tactic that doesn't scale well.  Ho hum...
hobbs Ticket [219264ffff]: 2 changes [History diff]2001-08-02 08:45:21
dgp Ticket [219264ffff]: 2 changes [History diff]2003-11-13 06:09:34
hobbs Closed ticket [219264ffff]. [History diff]2008-03-13 02:53:42
Log in (anonymous is fine) to add a comment.