In this document, there is a lot of text that can be matched
using regex. The benefit of using a regular expression is much
more flexible — albeit complex — syntax for text
pattern matching.
After you get the hang of regular expressions, also called
regexes, they will become a powerful tool for pattern matching.
TEST_DATA;
/*
* Use regex to highlight any occurence of the letters a-c
*/
$pattern = "/([a-c])/i";
echo preg_replace($pattern, "$1", $string);
/*
* Output the pattern you just used
*/
echo "\n
Pattern used: $pattern
";
?>
/*
* Set up several test date strings to ensure validation is working
*/
$date[] = '2010-01-14 12:00:00';
$date[] = 'Saturday, May 14th at 7pm';
$date[] = '02/03/10 10:00pm';
$date[] = '2010-01-14 102:00:00';
/*
* Date validation pattern
*/
$pattern = "/(\d*)/";
foreach ( $date as $d )
{
echo "
", preg_replace($pattern, "$1", $d), "
";
}
/*
* Output the pattern you just used
*/
echo "\n
Pattern used: $pattern
";
?>
Do'stlaringiz bilan baham: |