Re: [pcre-dev] several messages

Top Page
Delete this message
Author: ND
Date:  
To: Pcre-dev
Subject: Re: [pcre-dev] several messages
On 2012-01-22 17:22, Philip Hazel wrote:
> Even so, there is the problem of returning a zero-length partial match.I
> do not like this because, for a non-anchored pattern, you can *always*
> (well, almost always) find a zero-length partial match. Consider
> something simple like /abcd/ matched partially against "xyz". If
> zero-length partial matches are permitted, it would return a partial
> match at the end of the string, instead of no match. Is that useful?
> I have assumed that it is not useful.
>


This problem is a part of more common problem: If pattern contains
lookbehind than it may have useful zero-length partial matches.
To illustrate we can modified your example into: string 'abcd' matched
partially against 'xyz(?<=abcdxyz)'. Now it is obviously then partial
match becomes needed. What length it must have? It seems that this length
must be equal to maximum lookbehind length of the pattern. But I assumed
calculating this length is expensive task for PCRE. Main application may
knows this length exactly or presume that it can not exceed any constant
value (20 for example).

Thus I suggest that if pattern contains lookbehind then:
- pcre_exec can return zero-length partial hard matches
- PCRE must say (may be at compile time) to main application that
pattern contains lookbehind
- (optional) PCRE can calculate maximum lookbehind length of the pattern
(at study() or fullinfo() procedure).
If no lookbehind is in the pattern then no zero-length partial matches
allowed.