Re: [pcre-dev] Extracting non existant pattern name gives 0 …

Pàgina inicial
Delete this message
Autor: ph10
Data:  
A: Jayaprakasam, Kannan
CC: pcre-dev@exim.org
Assumpte: Re: [pcre-dev] Extracting non existant pattern name gives 0 length instead of PCRE_ERROR_NOSUBSTRING
On Wed, 18 Sep 2013, Jayaprakasam, Kannan wrote:

> When I match a subject that doesn't contain the return value, and I call
> pcre_get_named_substring(m_regexSPCall, sqlStmtUtf8, ovector, matchedCount, "retPort");
> lt doesn't return PCRE_ERROR_NOSUBSTRING but 0. Why does this happen?


This extract from the pcreapi man page explains the reason:

When any of these functions encounter a substring that is unset, which
can happen when capturing subpattern number n+1 matches some part of
the subject, but subpattern n has not been used at all, they return an
empty string. This can be distinguished from a genuine zero-length
substring by inspecting the appropriate offset in ovector, which is
negative for unset substrings.

The error PCRE_ERROR_NOSUBSTRING is given only for non-existent substrings.

Philip

--
Philip Hazel