comp.lang.ada
 help / color / mirror / Atom feed
From: r_srinivasan@my-deja.com
Subject: Re: Search Up
Date: 2000/11/22
Date: 2000-11-22T00:00:00+00:00	[thread overview]
Message-ID: <8vgs4h$s0a$1@nnrp1.deja.com> (raw)
In-Reply-To: 3A1BE4CA.24196926@crypt0.demon.co.uk

In article <3A1BE4CA.24196926@crypt0.demon.co.uk>,
  Hugo van der Sanden <hv@crypt0.demon.co.uk> 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.




  reply	other threads:[~2000-11-22  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-22  0:00 Search Up srini
2000-11-22  0:00 ` Hugo van der Sanden
2000-11-22  0:00   ` r_srinivasan [this message]
2000-11-27  0:00   ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox