I. Overview
1. Test of regular expression address: http://tool.chinaz.com/regex/
Second, the specific common regular expression
1. e-mail Regular expression:
1) \w[-\w.+]*@ ([a-za-z0-9][-a-za-z0-9]+\.) +[A-ZA-Z]{2,14}
2)\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
3) Analysis:
-- "\" is called "Skip character". Used to escape Some special symbols, such as ".", "/"
--"\w" is equivalent to [a-za-z0-9_]. Also matches Chinese characters
--"+" 1 to several times can also be written as {1}
-- parentheses to specify sub-expressions (also called groupings ), then you can specify the number of repetitions of this subexpression ([-+.] \w+)*
-- [-+.] The square brackets Expand the part is the Word value field .
-- . Match any character other than line break
4) Code example
<? PHP $email = ' [email protected] '; $preg = '/\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) */' ; $res Preg_match ($preg$email$preg _res); Var_dump (111,$res,$preg _res); exit;
-- Preg_match(): http://php.net/manual/zh/function.preg-match.php
2. URL expression:
1) [a-za-z]+://[^\s]+
2) Analysis:
-- ^
> in Word Value field (e.g. [^\w]) for negation (not included)--"Reverse selection"
> precedes the expression, indicating that it starts with the current character. (/^n/i, which means start with N).
--\s matches any whitespace character
Third, appendix
1. Common meta characters
Code description
. Match any character other than line break
\w match letters or numbers or underscores
\s matches any whitespace character
\d Matching numbers
\b Match the beginning or end of a word
^ Start of matching string
$ match End of string
2. Common Qualifiers
Code/Syntax Description
* Repeat 0 or more times
+ Repeat one or more times
? Repeat 0 or one time
{n} repeats n times
{n,} repeats n or more times
{N,m} repeats n to M times
3. Common antonyms
Code/Syntax Description
\w matches any characters that are not letters, numbers, underscores, kanji
\s matches any character that is not a white letter
\d matches any non-numeric character
\b Match is not where the word starts or ends
[^x] matches any character except X
[^aeiou] matches any character except the letters AEIOU
"Tamping PHP Basic series" PHP Regular expressions