Zero Quantifier
Identifier: regex.lint.quantifier.zero
When it triggers: A quantifier with a maximum of zero (e.g., {0} or {0,0}), which makes the element disappear. A repeat whose removal changes the match is left alone, as the optimizer leaves it: one holding a group, which still takes its number and may be called ((?<d>\d){0}(?&d)+, the way to define a subpattern), a backreference or a conditional, and one holding an assertion, which still tells PCRE2 where a match may start (/(?:x|(?=a)){0}\w/ never matches "\tb", where /\w/ does). Nor is a repeat reported in a pattern
where a call runs a repeat whose count may vary, a+ or a{2,3} but not a{2} nor a repeated call, in the group it calls or anywhere when the pattern calls itself whole: PCRE2 compiles
such a pattern by how all of it is written, and its JIT then misses matches its interpreter
finds. /(a+(?:x){0}b)c(?1)d/ and /(?:x){0}(a+b)c(?1)d/ find abcabd in abcabcabd with the
JIT, where /(a+b)c(?1)d/ finds nothing, from PCRE2 10.39 to 10.49.
Example:
// WARNING: {0} always matches zero occurrences
preg_match('/ab{0}c/', $input);
// PREFERRED: Remove the quantified element
preg_match('/ac/', $input);
Fix: Remove the quantified element or replace it with an empty pattern.
No repeat of zero copies is reported, no group is reported by regex.lint.group.empty or regex.lint.group.redundant, and neither the optimizer nor the Modernizer rewrites anything, in a pattern where a group repeated no time holds, in an alternative after its first, a repeat from zero without bound, an anchor, an assertion or a lookahead. PCRE2 passes over the first alternative of such a group alone and reads the second as the item the pattern opens with, so removing the group, or another before it, moves where a match may start: /(?:x|.*){0}a/ finds nothing in "ba", where /a/ finds a, and /(?:a|b){0}(?:x|^){0}a/ finds a where /(?:x|^){0}a/ finds nothing, from PCRE2 10.39 to 10.49, with the JIT and without.
Try it. Open /ab{0}c/ in the playground: the finding is in the Diagnostics tab.