to make complex expressions. They can assist you with achieving tasks, for example, validating email addresses, IP address and so forth
A regular expression is a sequence of characters that forms a search pattern. When you search for data in a text, you can use this search pattern to describe what you are searching for. A regular expression can be a single character, or a more complicated pattern
Let's see an example
<?php
$pattern = "/ca[kf]e/";
$text = "He was eating cake in the cafe.";
$matches = preg_match_all($pattern, $text, $array>
;
echo $matches . " matches were found.";
?>
Output

Try it here