PHP regular expression test
What is the output?
/*
$string = ‘This is a [templateVar]’;
preg_match_all(“/[[]]/”, $string, $matches);
foreach($matches[0] as $value)
{
echo $value;
}
*/
/*
$string = “Is this all there is?”;
echo(preg_match(“/[^A-J]/”,$string,$matches));
*/
/*
$string = “10 or 100 or 1000?”;
preg_match_all(“/d{2}/”, $string,$matches);
foreach($matches[0] as $value)
{
echo $value;
}
*/
/*
$string = ‘six at noon taxes’;
echo preg_match(“/s.x/”, $string, $matches);
*/
/*
$string = “Welcome to the new era”;
preg_match_all(“/[h-b]/”,$string,$matches);
foreach($matches[0] as $value)
{
echo $value;
}
*/
/*
$keywords = preg_split(“/[s,]+/”, “php, regular expressions”);
print_r( $keywords );
*/
/*
$string = ‘%Give_result%’;
preg_match_all(“/[W]/”, $string, $matches);
foreach($matches[0] as $value)
{
echo $value;
}
*/
/*
$keywords = ‘$40 for a g3/400’;
$keywords = preg_quote($keywords, ‘/’);
echo $keywords;
*/
/*
preg_match(‘/(?:D+|<d+>)*[!?]/’, ‘foobar foobar foobar’);
if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR) {
echo ‘Backtrack limit was exhausted!’;
}
*/
/*
$string = ‘The Lord is the God’;
if(preg_match(“/the+(?!is)/i”, $string,$match))
{
print_r($match);
}
*/
/*
$string = ‘The GOD is the Lord.’;
$string = preg_replace(“/The/g”, ‘Ze’, $string);
echo $string;
*/
/*
$str = ‘string’;
$chars = preg_split(‘//’, $str, -1, PREG_SPLIT_NO_EMPTY);
print_r($chars);
*/
/*
$string = ‘ball’;
echo preg_match(“/b[aoiu]l/”, $string, $matches);
*/
/*
$string = “Is this all there is?”;
preg_match_all(“/[a-h]/”,$string,$matches);
foreach($matches[0] as $value)
{
echo $value;
}
*/
/*
$str=”This lathe turns wood.”;
echo(preg_match(“/Btheb/”, $str));
*/
/*
$string = ‘I live in the whitehouse’;
if(preg_match(“/(?<!blue)house/i”, $string))
{
echo ‘Found a match’;
}
else
{
echo ‘No match found’;
}
*/
$string = “1, 100 or 1000?”;
preg_match_all(“/10*/”,$string,$matches);
foreach($matches[0] as $value)
{
echo $value;
}
echo” //////////////////////”;
///echo preg_replace(“/([Cc]opyright) 200(3|4|5|6)/”, “$1 2007”, “Copyright 2005”);
/*
$names = array(‘Andrew’,’John’,’Peter’,’Nastin’,’Bill’);
$output = preg_grep(‘/^[a-m]/i’, $names);
print_r( $output );
*/
$string = ‘This is the {_FOO_} brought to you by {_BAR_}’;
$template_vars=array(“FOO” => “The PHP Way”, “BAR” => “PHPro.orG”);
$string = preg_replace(“/{_(.*?)_}/ime”, “$template_vars[‘$1’]”,$string);
echo $string;