comp.lang.ada
 help / color / mirror / Atom feed
* Search Up
@ 2000-11-22  0:00 srini
  2000-11-22  0:00 ` Hugo van der Sanden
  0 siblings, 1 reply; 4+ messages in thread
From: srini @ 2000-11-22  0:00 UTC (permalink / raw)


folks,

Can anyone please give me a hint as to how I will solve this problem :

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?

Any and all hints would be welcome.

regards

srini




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Search Up
  2000-11-22  0:00 Search Up srini
@ 2000-11-22  0:00 ` Hugo van der Sanden
  2000-11-22  0:00   ` r_srinivasan
  2000-11-27  0:00   ` Robert A Duff
  0 siblings, 2 replies; 4+ messages in thread
From: Hugo van der Sanden @ 2000-11-22  0:00 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Search Up
  2000-11-22  0:00 ` Hugo van der Sanden
@ 2000-11-22  0:00   ` r_srinivasan
  2000-11-27  0:00   ` Robert A Duff
  1 sibling, 0 replies; 4+ messages in thread
From: r_srinivasan @ 2000-11-22  0:00 UTC (permalink / raw)


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.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Search Up
  2000-11-22  0:00 ` Hugo van der Sanden
  2000-11-22  0:00   ` r_srinivasan
@ 2000-11-27  0:00   ` Robert A Duff
  1 sibling, 0 replies; 4+ messages in thread
From: Robert A Duff @ 2000-11-27  0:00 UTC (permalink / raw)


Hugo van der Sanden <hv@crypt0.demon.co.uk> writes:

>...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, ...

An editor ought to be able to search for strings (or regexps) that
contain multiple lines.  Emacs can do this, for example.

- Bob




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-11-27  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-22  0:00 Search Up srini
2000-11-22  0:00 ` Hugo van der Sanden
2000-11-22  0:00   ` r_srinivasan
2000-11-27  0:00   ` Robert A Duff

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