Home > Article > Backend Development > Regular expressions for review of PHP knowledge points_PHP tutorial
Previous article http://www.BkJia.com/kf/201202/118458.html
//Technical knowledge of regular expressions
// []Define character set and example [a-z] [A-Z] [0-9] [frnt]
//locator ^[A-Z][0-9]$ starts and ends
//Quantifier * + ? {n} {m,n} {n.} refers to the number of repetitions
//Select|
//Printable characters: The characters represented by 33-127 in ASCII are the symbols we can see. Space, delete, carriage return, cancel, etc. are typically non-printable characters
//POSOX regular expression
//Commonly used functions
echo "
";
$b4 = "abc";
$pattern = "[[:alpha:]]";
echo ereg($pattern,$b4);
//Output 1
//eregi() unsigned
$b7 = "asd&ass@ass&adfdf";
$pattern1 = "&";
$pattern2 = "[&@]";
print_r(split($pattern1,$b7));
print_r(split($pattern2,$b7));
echo "
";
$b8 = "helloworld";
$pattern3 = "world";
$replacement1 = "persion";
echo ereg_replace($pattern3,$replacement1,$b8);
echo "
";
echo sql_regcase("abcdefg");
//Output: [Aa][Bb][Cc][Dd][Ee][Ff][Gg]
//Perl regular expression perl is an additional extension based on posix support d digits D non-digits s blank S non-blank w alphanumeric symbols underline W non-alphanumeric symbols underline
//Commonly used function array preg_grep (string pattern, array input)
echo "
";
$w1 = array("adad","adad4","asda","1asf3","sdfs");
$fl_array = preg_grep ("/^D{1,}$/", $w1);//The emphasis here is {1,} instead of {1.} in posix
print_r($fl_array);
echo "
";
echo preg_match ("/a/","abc");
//Output 1
echo "
";
//b represents the boundary of the word
if (preg_match ("/bwebb/i", "PHP is the web scripting language of choice.")) {
Print "A match was found.";
} else {
Print "A match was not found.";
}
if (preg_match ("/bwebb/i", "PHP is the website scripting language of choice.")) {
Print "A match was found.";
} else {
Print "A match was not found.";
}
//Especially used when matching email addresses
echo "
";
$pattern5 = "/[*]+/";
$w3 = "aaa***bbb*ccc";
print_r(preg_split($pattern5,$w3));
echo "
";
$pattern6 = "/world/";
$content2 = "girl";
$tre = "hello world";
echo preg_replace($pattern6,$content2,$tre);
//string preg_quote ( string str [, string delimiter] ) escape
echo "
";
$keywords = "$40 for a g3/400";
$keywords = preg_quote ($keywords, "/");//If the / here is not added, the / in g3/400 will not be escaped;
echo $keywords;
Excerpted from kaituozhe345’s column