[pcre-dev] [Bug 2645] error when trying to substitute an opt…

Pàgina inicial
Delete this message
Autor: admin
Data:  
A: pcre-dev
Assumpte: [pcre-dev] [Bug 2645] error when trying to substitute an optional capture group that was not matched
https://bugs.exim.org/show_bug.cgi?id=2645

Philip Hazel <Philip.Hazel@???> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED


--- Comment #1 from Philip Hazel <Philip.Hazel@???> ---
This is not a bug. It is a documented effect. There is an option to change the
default behaviour; this is what the documentation says:

"PCRE2_SUBSTITUTE_UNSET_EMPTY causes unset capture groups (including unknown
groups when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) to be treated as empty
strings when inserted as described above. If this option is not set, an attempt
to insert an unset group causes the PCRE2_ERROR_UNSET error. This option does
not influence the extended substitution syntax described below."

The extended syntax (applied when the PCRE2_SUBSTITUTE_EXTENDED option is set)
provides a more extensive facility:

${<n>:-<string>}
${<n>:+<string1>:<string2>}

"As before, <n> may be a group number or a name. The first form specifies a
default value. If group <n> is set, its value is inserted; if not, <string> is
expanded and the result inserted. The second form specifies strings that are
expanded and inserted when group <n> is set or unset, respectively."

If your regex101 example is using PCRE2, presumably it is setting the
PCRE2_SUBSTITUTE_UNSET_EMPTY option.

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