<?php
$my_email = "name@company.com";
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";
}
?>
if(!preg_match('/^[a-zA-Z]+$/',$input)) {
// String contains not allowed characters ...
}
<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>
<?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";
}
?>
$utterance = 'This is a brown bear with 7 kids';
$template = 'This is a {color} bear with {kids} kids';
$templateRegex = '/' . preg_replace('/{(.*?)}/', '(?<1>.*?)', $template) . '/';
$matches = [];
preg_match($templateRegex, $utterance, $matches);
var_dump($matches);
<?php
$my_text="I Love Regular Expressions";
$my_array = preg_split("/ /", $my_text);
print_r($my_array );
?>
<?php
function_name('/pattern/',subject);
?>
int preg_match (string pattern, string string [, array pattern_array], [, int $flags [, int $offset]]]);
preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) : int