From 646ba2c4d05bf02216c0f7c40bb5f7307e7d8c16 Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Fri, 10 Jul 2026 13:58:54 +0200 Subject: [PATCH 1/3] ext/pcre: Document variable-length lookbehind and 128-char subpattern names (PCRE2 10.44) --- reference/pcre/pattern.syntax.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/reference/pcre/pattern.syntax.xml b/reference/pcre/pattern.syntax.xml index f1315e2a0bab..ae3d1f5c9860 100644 --- a/reference/pcre/pattern.syntax.xml +++ b/reference/pcre/pattern.syntax.xml @@ -1510,6 +1510,10 @@ also by name. There are two alternative syntaxes (?<name>pattern) and (?'name'pattern). + + As of PHP 8.4.0, which bundles PCRE2 10.44, the maximum length of a + subpattern name is 128 characters; prior to PHP 8.4.0 it was 32 characters. + Sometimes it is necessary to have multiple matching, but alternating @@ -1915,6 +1919,14 @@ at the ends of strings; an example is given at the end of the section on once-only subpatterns. + + The fixed-length restriction described above applies prior to PHP 8.4.0. + As of PHP 8.4.0, which bundles PCRE2 10.44, a lookbehind assertion may match + strings of variable length: alternatives of differing lengths (such as + (?<!dogs?|cats?)) and top-level branches that can match + more than one length (such as (?<=ab(c|de))) are now + permitted, up to an implementation-defined maximum length. + Several assertions (of any sort) may occur in succession. For example, From 2856871de16c0c496886b42406d6c552816c9c42 Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Sun, 16 Aug 2026 14:24:00 +0200 Subject: [PATCH 2/3] Update reference/pcre/pattern.syntax.xml Co-authored-by: Jordi Kroon --- reference/pcre/pattern.syntax.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/pcre/pattern.syntax.xml b/reference/pcre/pattern.syntax.xml index ae3d1f5c9860..e58987c93ad6 100644 --- a/reference/pcre/pattern.syntax.xml +++ b/reference/pcre/pattern.syntax.xml @@ -1512,7 +1512,7 @@ As of PHP 8.4.0, which bundles PCRE2 10.44, the maximum length of a - subpattern name is 128 characters; prior to PHP 8.4.0 it was 32 characters. + subpattern name is 128 characters; previously it was 32 characters. From eca63476bdd405b9170b619eeebebe5cdbc80917 Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Sun, 16 Aug 2026 14:30:48 +0200 Subject: [PATCH 3/3] ext/pcre: describe the current lookbehind behaviour first Document variable-length lookbehind as the current behaviour and move the fixed-length restriction below, as historical information for versions prior to PHP 8.4.0. --- reference/pcre/pattern.syntax.xml | 57 +++++++++++++++++-------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/reference/pcre/pattern.syntax.xml b/reference/pcre/pattern.syntax.xml index e58987c93ad6..9e832051bc79 100644 --- a/reference/pcre/pattern.syntax.xml +++ b/reference/pcre/pattern.syntax.xml @@ -1878,37 +1878,24 @@ when the next three characters are "bar". A lookbehind assertion is needed to achieve this effect. - + Lookbehind assertions start with (?<= for positive assertions and (?<! for negative assertions. For example, (?<!foo)bar does find an occurrence of "bar" that is not preceded by - "foo". The contents of a lookbehind assertion are restricted - such that all the strings it matches must have a fixed - length. However, if there are several alternatives, they do - not all have to have the same fixed length. Thus - - (?<=bullock|donkey) - - is permitted, but + "foo". A lookbehind assertion may match strings of variable + length, up to an implementation-defined maximum length. + Alternatives of differing lengths, such as (?<!dogs?|cats?) - causes an error at compile time. Branches that match different - length strings are permitted only at the top level of - a lookbehind assertion. This is an extension compared with - Perl 5.005, which requires all branches to match the same - length of string. An assertion such as + and top-level branches that can match more than one length, such as (?<=ab(c|de)) - is not permitted, because its single top-level branch can - match two different lengths, but it is acceptable if rewritten - to use two top-level branches: - - (?<=abc|abde) + are permitted. The implementation of lookbehind assertions is, for each alternative, to temporarily move the current position back @@ -1918,14 +1905,32 @@ once-only subpatterns can be particularly useful for matching at the ends of strings; an example is given at the end of the section on once-only subpatterns. - + - The fixed-length restriction described above applies prior to PHP 8.4.0. - As of PHP 8.4.0, which bundles PCRE2 10.44, a lookbehind assertion may match - strings of variable length: alternatives of differing lengths (such as - (?<!dogs?|cats?)) and top-level branches that can match - more than one length (such as (?<=ab(c|de))) are now - permitted, up to an implementation-defined maximum length. + Prior to PHP 8.4.0, which bundles PCRE2 10.44, the contents of a lookbehind + assertion were restricted such that all the strings it matched had to have a + fixed length. If there were several alternatives, they did not all have to + have the same fixed length, thus + + (?<=bullock|donkey) + + was permitted, but + + (?<!dogs?|cats?) + + caused an error at compile time. Branches that matched different + length strings were permitted only at the top level of + a lookbehind assertion. This was an extension compared with + Perl 5.005, which required all branches to match the same + length of string. An assertion such as + + (?<=ab(c|de)) + + was not permitted, because its single top-level branch could + match two different lengths, but it was acceptable if rewritten + to use two top-level branches: + + (?<=abc|abde) Several assertions (of any sort) may occur in succession.