Home >Backend Development >PHP Tutorial >regularexpression php regular expression regar expression
Introduction: When writing programs or web pages that process strings, there is often a need to find strings
that match certain complex rules. Regular expressions are the syntax used to describe these rules.
Example: When judging the user's email address format, mobile phone number format, or collecting the content of other people's web pages.
php also often uses regular expressions. PHP has two commonly used regular expression functions: preg_match and ereg.
I just watched preg_match today. Its specific writing method is preg_match (mode, string subject, array matches);
The following is an example I wrote.
Copy the code The code is as follows:
php
$mode="/[^8s]/";//Matching module
$str="sssjj88d";//Matching content
echo "
Copy the code The code is as follows:
$ mode="/d{2,4}(.*)d{1,2}\1d{1,2}/";//The simpler the matching module is, the better
//$mode="/2009 (.*)9\1(10)/";
$str="2011/9/10";
if(preg_match($mode,$str,$arr)){
echo "Match successfully"."< ;br/>".$arr[0]."
";
}
else{
echo "Match failed";
}
?>
The above introduces the regular expression php regular expression regar expression, including the content of regular expression. I hope it will be helpful to friends who are interested in PHP tutorials.