Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions reference/pcre/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@
<entry>
This flag tells <function>preg_match</function> and
<function>preg_match_all</function> to include unmatched subpatterns in
<varname>$matches</varname> as &null; values. Without this flag, unmatched
subpatterns are reported as empty strings, as if they were empty matches.
<varname>$matches</varname> as &null; values, including trailing
unmatched subpatterns. Without this flag, non-trailing unmatched
subpatterns are reported as empty strings, while trailing unmatched
subpatterns are omitted from the results entirely.
Setting this flag allows to distinguish between these two cases.
</entry>
<entry>7.2.0</entry>
Expand Down
20 changes: 16 additions & 4 deletions reference/pcre/functions/preg-match-all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,14 @@ Array
<varlistentry>
<term><constant>PREG_UNMATCHED_AS_NULL</constant></term>
<listitem>
<para>
If this flag is passed, unmatched subpatterns are reported as &null;;
otherwise they are reported as an empty <type>string</type>.
</para>
<simpara>
If this flag is passed, unmatched subpatterns are reported as &null;
and are always included in the results (including trailing ones).
Without this flag, unmatched subpatterns that are followed by a
matched subpattern are reported as an empty <type>string</type>,
while trailing unmatched subpatterns are omitted from the results
entirely.
</simpara>
</listitem>
</varlistentry>
</variablelist>
Expand Down Expand Up @@ -301,6 +305,14 @@ Array
</row>
</thead>
<tbody>
<row>
<entry>7.4.0</entry>
<entry>
When the <constant>PREG_UNMATCHED_AS_NULL</constant> flag is used,
trailing unmatched capturing groups are now also included in the
result with the value &null;. Previously, they were omitted.
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
Expand Down
38 changes: 36 additions & 2 deletions reference/pcre/functions/preg-match.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ Array
<term><constant>PREG_UNMATCHED_AS_NULL</constant></term>
<listitem>
<para>
If this flag is passed, unmatched subpatterns are reported as &null;;
otherwise they are reported as an empty <type>string</type>.
If this flag is passed, unmatched subpatterns are reported as &null;
and are always included in the results (including trailing ones).
Without this flag, unmatched subpatterns that are followed by a
matched subpattern are reported as an empty <type>string</type>,
while trailing unmatched subpatterns are omitted from the results
entirely.
<informalexample>
<programlisting role="php">
<![CDATA[
Expand All @@ -129,6 +133,12 @@ preg_match('/(a)(b)*(c)/', 'ac', $matches);
var_dump($matches);
preg_match('/(a)(b)*(c)/', 'ac', $matches, PREG_UNMATCHED_AS_NULL);
var_dump($matches);

// Trailing unmatched subpatterns:
preg_match('/(a)(b)?(c)?/', 'a', $matches);
var_dump($matches);
preg_match('/(a)(b)?(c)?/', 'a', $matches, PREG_UNMATCHED_AS_NULL);
var_dump($matches);
?>
]]>
</programlisting>
Expand All @@ -155,6 +165,22 @@ array(4) {
[3]=>
string(1) "c"
}
array(2) {
[0]=>
string(1) "a"
[1]=>
string(1) "a"
}
array(4) {
[0]=>
string(1) "a"
[1]=>
string(1) "a"
[2]=>
NULL
[3]=>
NULL
}
]]>
</screen>
</informalexample>
Expand Down Expand Up @@ -270,6 +296,14 @@ Array
</row>
</thead>
<tbody>
<row>
<entry>7.4.0</entry>
<entry>
When the <constant>PREG_UNMATCHED_AS_NULL</constant> flag is used,
trailing unmatched capturing groups are now also included in the
result with the value &null;. Previously, they were omitted.
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
Expand Down