regex check php code example

Example 1: find substring regx php

if (preg_match("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
}

Example 2: php regex

preg_match('/(foo)(bar)(baz)/', 'foobarbaz', $matches, PREG_OFFSET_CAPTURE);

Example 3: php regex test

* Lets suppose, we want to test a string variable that contain exactly "Abc" in it.
So we can do it using .......

<?php
$str = "I am Abc.";
$pattern = "/Abc/i";
if (preg_match($pattern, $str))
{
	echo "True.";
}
else
{
	echo "False.";
}
?>