PHP: Regular expressions - avoid pattern quantifiers in the preg_match_all

Preg-match is the Perl regular expression-match engine for PHP.



It turns out that, additional match quantifiers should be avoided.

To demonstrate this, follow this code snippet:

The return value of preg_match_all in this case was 65, basically a count of each character of the input.



count($matches) will correctly yield '2', as empty array-elements are not counted.



Note: preg_match_all is a shortcut function which adds an quantifier to the match. As such the correct pattern will be /(....)/ not /(....)*/
LihatTutupKomentar