Get your own PHP server Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>Regex Modifier: cat|dog|fish</h1>
<p>How many occurrences of either "cat", "dog", or "fish" are in the text "We have three dogs, one fish, but no cats":</p>
<?php
$txt = "We have three dogs, one fish, but no cats";
$pattern = "/cat|dog|fish/";
echo preg_match_all($pattern, $txt);
?>  
<p>The matches were found here:</p>
<?php
echo preg_replace($pattern, "#", $txt);
?>  
<p>(Each match was replaced by a # character)</p>
</body>
</html>

Regex Modifier: cat|dog|fish

How many occurrences of either "cat", "dog", or "fish" are in the text "We have three dogs, one fish, but no cats":

3

The matches were found here:

We have three #s, one #, but no #s

(Each match was replaced by a # character)