PHP Knowledge Point Review Regular expression _php tutorial

Source: Internet
Author: User
Tags perl regular expression posix printable characters
Last article http://www.BkJia.com/kf/201202/118458.html

Technical knowledge of regular expressions


[] Define character sets and example [A-z] [a-z] [0-9] [\f\r\n\t]


Locator ^[a-z][0-9]$ Start end


Quantifier * +? {n} {m,n} {N.} Refers to the number of repetitions


Select |


Printable characters: 33-127 characters in ASCII, that is, we can see the symbol space, delete, enter, cancel and so on is typically non-printable characters


Posox Regular Expressions
Common functions
echo "
";
$b 4 = "abc";
$pattern = "[[: Alpha:]]";
Echo Ereg ($pattern, $b 4);
Output 1
Eregi () unsigned





$b 7 = "ASD&ASS@ASS&ADFDF";

$pattern 1 = "&";
$pattern 2 = "[&@]";
Print_r (Split ($pattern 1, $b 7));
Print_r (Split ($pattern 2, $b 7));


echo "
";
$b 8 = "HelloWorld";
$pattern 3 = "World";
$replacement 1 = "persion";
Echo ereg_replace ($pattern 3, $replacement 1, $b 8);


echo "
";
Echo sql_regcase ("ABCDEFG");
Output: [Aa][bb][cc][dd][ee][ff][gg]


Perl Regular Expression Perl is an additional extension on the basis of POSIX support \d digital \d non-numeric \s blank \s non-whitespace \w letter mathematical symbol underline \w non-alphanumeric sign underline

Common functions Array Preg_grep (string pattern, array input)
echo "
";
$w 1 = Array ("Adad", "Adad4", "Asda", "1asf3", "SDFs");
$FL _array = Preg_grep ("/^\d{1,}$/", $w 1);//The emphasis here is on {1,} instead of {1} in POSIX.
Print_r ($FL _array);


echo "
";
Echo Preg_match ("/a/", "abc");
Output 1


echo "
";
\b represents the boundary of a word
if (Preg_match ("/\bweb\b/i", "PHP is the Web scripting language of choice.")) {
Print "A match was found.";
} else {
Print "A match is not found.";
}


if (Preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice.")) {
Print "A match was found.";
} else {
Print "A match is not found.";
}
Especially when matching e-mail is commonly used


echo "
";
$pattern 5 = "/[\*]+/";
$w 3 = "AAA***BBB*CCC";
Print_r (Preg_split ($pattern 5, $w 3));


echo "
";
$pattern 6 = "/world/";
$content 2 = "Girl";
$tre = "Hello World";
Echo Preg_replace ($pattern 6, $content 2, $tre);


String Preg_quote (String str [, String delimiter]) escaped
echo "
";
$keywords = "g3/400 for a";
$keywords = Preg_quote ($keywords, "/");//If it is not added, it will not escape the g3/400;
Echo $keywords;

Excerpt from kaituozhe345 's column

http://www.bkjia.com/PHPjc/478415.html www.bkjia.com true http://www.bkjia.com/PHPjc/478415.html techarticle technical knowledge of http://www.2cto.com/kf/201202/118458.html//Regular expressions//[] defining character sets and example [A-z] [a-z] [0-9] [\f\r\n\t]//Locators ^[ a-z][0-9]$ opening End//volume ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.