Re: [pcre-dev] PCRE bug

Top Page
Delete this message
Author: Philip Hazel
Date:  
To: Srinivas R Thota
CC: pcre-dev
Subject: Re: [pcre-dev] PCRE bug
On Thu, 10 Apr 2008, Srinivas R Thota wrote:

> Thanks for your response, But in my use case it is not possible to
> feed the regexp manually its autogenerated, and may be its not
> possible to determine which regexp component can consume maximum
> length, Could you point if there is any way I can changes this in the
> PCRE code, to make it match longest string.


If you do not need the capturing parentheses, you can use
pcre_dfa_exec() instead of pcre_exec(). However, I think perhaps you do
want to do capturing, so you probably cannot use this method.

There is no way (without complete redesign) to change the code to make
it carry on searching and remember which was the longest string (and
also remember the relevant captured strings for the longest match). I do
not know how to do this. PCRE just isn't designed that way - it is
designed to be Perl-compatible.

The only possible approach would be somehow to make use of PCRE's
"callout" feature, possibly using the PCRE_AUTO_CALLOUT flag, and when
the callout happens at the end of the pattern, have the callout function
remember everything before returning a positive number, to make matching
continue. This sounds very complicated, and it will also make PCRE run a
lot more slowly. See "man pcrecallout" for details of callouts.

Philip

--
Philip Hazel