[pcre-dev] [Bug 1694] Backward search

Page principale
Supprimer ce message
Auteur: admin
Date:  
À: pcre-dev
Sujet: [pcre-dev] [Bug 1694] Backward search
https://bugs.exim.org/show_bug.cgi?id=1694

Philip Hazel <ph10@???> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|bug                         |wishlist


--- Comment #2 from Philip Hazel <ph10@???> ---
True backwards search is not implemented in PCRE, and is unlikely to be
implemented in any short timescale. It would need a complete rewrite and a
redesign of the compiled code, and in fact would probably be best done as a
different set of functions; otherwise frequent testing for "am I going forwards
or backwards" would seriously hit performance. A major project.

I know of a text editor that uses PCRE and which has a "backwards" mode. This
application is searching line-by-line. When it is going backwards, it needs to
find the last match in the current line. This you can do by a simple trick of
modifying the pattern. If your regex is P, change it to (.*)P and then apply it
to the line. The result is the last occurrence of P in the line. This works
because (.*) is "greedy". It uses up the entire line; the matcher then tries to
match P. If this fails, it moves back by one character and tries again. In
other words, although it is matching P itself in a forwards direction, it is
doing the search from the end of the line, which is "backwards" enough for this
text editing application. (Of course, to find the previous occurrence in the
line you just try again with a shortened line.)

Partial matching is not involved in this application. I can see no way of using
it.

--
You are receiving this mail because:
You are on the CC list for the bug.