preg_match pattern in php code example
Example 1: preg_match in php
<?php
$str = "Check For Testing.";
if (preg_match("/\bCheck\b/i", $str, $match))
echo "Matched!";
else
echo "not matched";
?>
Example 2: preg_match in php
<?php
$my_email = "[email protected]";
if (preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/", $my_email)) {
echo "$my_email is a valid email address";
}
else
{
echo "$my_email is NOT a valid email address";
}
?>
Example 3: preg_match in php
<?php
$my_url = "www.guru99.com";
if (preg_match("/guru/", $my_url))
{
echo "the url $my_url contains guru";
}
else
{
echo "the url $my_url does not contain guru";
}
?>