Multiple preg match

How is it possible to have several regexp to be performed by a preg_match? I know preg_replace accepts several regexp as an array but in this case there is nothing to replace and I just need to see if there is a match.
Is it possible to have several regexp in a single preg match perform?

You can combine multiple patterns in a single regex with the pipe character in parentheses:

preg_match('/(cats?|dogs?|re.*tion)/', $string, $matches);
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.