Re: [pcre-dev] 'Hard' partial matching don't work with some …

Top Page
Delete this message
Author: Philip Hazel
Date:  
To: ND
CC: pcre-dev
Subject: Re: [pcre-dev] 'Hard' partial matching don't work with some assertions
On Sat, 21 Jan 2012, ND wrote:

> This sentence is not about example above. In my example result must not be a
> partial match. Result must be "not match".


Your example was

/\z/
\P\Pa

What happens is this:

1. Start looking at "a": this fails to match \z; match fails at position 0.

2. Start again at position 1.

3. The item to be matched is \z:

Are we at the end of the string? (If not, return no match.)
Yes, we are. That is, \z does match.
Are we doing partial matching?
Yes, we are.
Have we inspected at least one character?
No, we have not, so there cannot be a partial match.
(If we had inspected one character, there would be a partial match.)
It's not a partial match, but we have successfully matched \z, so
carry on matching.

4. Next item is "end of pattern" so the result is a match.

The documentation for this now reads as follows:

If PCRE_PARTIAL_HARD is set for pcre_exec() or pcre16_exec(),
PCRE_ERROR_PARTIAL is returned as soon as a partial match is found,
without continuing to search for possible complete matches. This
option is "hard" because it prefers an earlier partial match over a
later complete match. For this reason, the assumption is made that the
end of the supplied subject string may not be the true end of the
available data, and so, if \z, \Z, \b, \B, or $ are encountered at the
end of the subject, the result is PCRE_ERROR_PARTIAL, provided that at
least one character in the subject has been inspected.

Note that is says "may not be", not "is not". The last phrase
("provided...") is what I have just added.

If you add a partial match option to a given matching operation, the
previous result (which could be match or no match) may change to a
partial match. However, it will not change a match into a no match,
which is what you are suggesting.

Philip

--
Philip Hazel