From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,903de1597bba5a2e X-Google-Attributes: gid103376,public X-Google-Thread: f8362,903de1597bba5a2e X-Google-Attributes: gidf8362,public From: r_srinivasan@my-deja.com Subject: Re: Search Up Date: 2000/11/22 Message-ID: <8vgs4h$s0a$1@nnrp1.deja.com>#1/1 X-Deja-AN: 696693700 References: <3A1BF2E3.F2C51F59@worldnet.att.net> <3A1BE4CA.24196926@crypt0.demon.co.uk> X-Http-Proxy: 1.0 cinohnet1edcge.indsys.ge.com:80 (Squid/2.2.STABLE4), 1.0 proxy01.motors.ge.com:80 (Squid/2.3.STABLE4), 1.0 x70.deja.com:80 (Squid/1.1.22) for client 3.29.29.124, 3.34.221.228, 12.39.22.21 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed Nov 22 16:27:04 2000 GMT X-MyDeja-Info: XMYDJUIDr_srinivasan Newsgroups: comp.theory,comp.lang.ada X-Http-User-Agent: Mozilla/4.74 [en] (WinNT; U) Date: 2000-11-22T00:00:00+00:00 List-Id: In article <3A1BE4CA.24196926@crypt0.demon.co.uk>, Hugo van der Sanden wrote: I was afraid that might be the case. (!) I am not able to but anyone can explain how let us say emacs ^R search is implemented? thanks srini > srini wrote: > > I am developing an editor. It has the ability to "search" for a given > > regular expression. Now, I would like to add the ability to search > > backwards from a given position. I guess it is really not backwards but > > the last occurance of the expression. > > > > Perhaps I can reverse the string, reverse the regex and then compile the > > regexp and search. Will this be valid? > > That depends a lot on what style of regexps you support: if you were > supporting all the regexp features of the latest version of perl, for > example, you would not be able to do this. For smaller subsets it may be > possible: ^, $, |, ., +, *, ?, {m,n}, [class] should all be reversible, > I think; backreferences are where it starts to get much trickier. > > If you must find exactly the same matches that a forward search would > find, this will fail on overlapping matches: "abaab" =~ /a./ will match > the final "ab" on a reverse search, where it would have matched the "aa" > on a (repeated) forward search. In that case, you might want to do the > best you can by searching backwards a line at a time until you find a > line that matches, and then search forwards repeatedly to find the last > match on the line. (Of course, this may still fail to find the correct > substring for overlapping matches that cross line boundaries.) > > HTH, > > Hugo > Sent via Deja.com http://www.deja.com/ Before you buy.