Sometimes, you might stumble upon a situation where an amount of occurrences is needed, but not the occurrences
themselves. In that case,
pattern()->count() is perfect:
\Countable, so you can use PHP build-in methods, like
If your pattern does not match the subject,
count() simply returns
Every use of
pattern() with an invalid pattern will cause
You might be tempted to use
count() to check whether your subject was matched by the pattern, since
return any matches...
This is because
count() will go through each occurrence of a pattern in a subject, counting it; whereas
will return right after it finds the first occurrence.