# Collation summary based on php common regular expressions

• 2020-06-12 08:38:45
• OfStack

As shown below:

``````
"^/d+\$"　　// Non-negative integers (positive integers  + 0 )
"^[0-9]*[1-9][0-9]*\$"　　// Positive integer
"^((-/d+)|(0+))\$"　　// Nonpositive integers (negative integers)  + 0 )
"^-[0-9]*[1-9][0-9]*\$"　　// Negative integer
"^-?/d+\$"　　　　// The integer
"^/d+(/./d+)?\$"　　// Non-negative floating-point Numbers (positive floating-point Numbers)  + 0 )
"^(([0-9]+/.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*/.[0-9]+)|([0-9]*[1-9][0-9]*))\$"　　// Are floating point Numbers
"^((-/d+(/./d+)?)|(0+(/.0+)?))\$"　　// Non-positive floating-point Numbers (negative floating-point Numbers)  + 0 )
"^(-(([0-9]+/.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*/.[0-9]+)|([0-9]*[1-9][0-9]*)))\$"　　// Negative floating point number
"^(-?/d+)(/./d+)?\$"　　// Floating point Numbers
"^[A-Za-z]+\$"　　// by 26 A string of six English letters
"^[A-Z]+\$"　　// by 26 A string consisting of two uppercase letters
"^[a-z]+\$"　　// by 26 A string of lowercase English letters
"^[A-Za-z0-9]+\$"　　// By the Numbers and 26 A string of six English letters
"^/w+\$"　　// By the Numbers, 26 A string of two English letters or underscores
"^[a-zA-z]+://(/w+(-/w+)*)(/.(/w+(-/w+)*))*(/?/S*)?\$"　　//url
/^(d{2}|d{4})-((0([1-9]{1}))|(1[1|2]))-(([0-2]([1-9]{1}))|(3[0|1]))\$/   //   years - month - day
/^((0([1-9]{1}))|(1[1|2]))/(([0-2]([1-9]{1}))|(3[0|1]))/(d{2}|d{4})\$/   //  month / day / years
"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)\$"   //Emil
/^((/+?[0-9]{2,4}/-[0-9]{3,4}/-)|([0-9]{3,4}/-))?([0-9]{7,8})(/-[0-9]+)?\$/     // The phone number
Regular expressions matching Chinese characters:  [/u4e00-/u9fa5]
Matches double-byte characters ( Including Chinese characters ) : [^/x00-/xff]
A regular expression matching an empty line: /n[/s| ]*/r
matching HTML Regular expressions for tags: /<(.*)>.*<///1>|<(.*) //>/
A regular expression matching Spaces at the beginning and end: (^/s*)|(/s*\$)
matching Email Regular expression of address: /w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
Match the url URL Is the regular expression of: ^[a-zA-z]+://(//w+(-//w+)*)(//.(//w+(-//w+)*))*(//?//S*)?\$
Match whether the account is valid ( The letter begins, allow 5-16 Byte, allowing alphanumeric underscore ) : ^[a-zA-Z][a-zA-Z0-9_]{4,15}\$
Match domestic phone number: (/d{3}-|/d{4}-)?(/d{8}|/d{7})?
Match the tencent QQ No. : ^[1-9]*[1-9][0-9]*\$

Metacharacters and their behavior in the context of regular expressions:
/  Will the 1 The characters are marked as 1 A special character, or 1 A literal character, or 1 A backward reference, or 1 a 8 Base escape character.
^  Matches the starting position of the input string. If it's set  RegExp  The object's Multiline  Properties, ^  Also match  '/n'  or  '/r'  The position after that.
\$  Matches the end of the input string. If it's set  RegExp  The object's Multiline  Properties, \$  Also match  '/n'  or  '/r'  The previous position.
*  Match the previous subexpression zero or more times.
+  Match the previous subexpression 1 Times or times. +  Is equivalent to  {1,} .
?  Match the previous subexpression zero times or 1 Times. ?  Is equivalent to  {0,1} .
{n} n  is 1 Non - negative integers, determined by a match n  Times.
{n,} n  is 1 Non-negative integers, at least matching n  Times.
{n,m} m  and  n  Are non-negative integers, where n <= m . At least match  n  Secondary and maximum matches  m  Times. There can be no space between a comma and two Numbers.
?  When the character follows any 1 Three other qualifiers  (*, +, ?, {n}, {n,}, {n,m})  Later, the matching pattern is non-greedy. The non-greedy pattern matches the searched string as little as possible, while the default greedy pattern matches the searched string as much as possible.
.  matches  "/n"  Any single character other than. To match include  '/n'  Inside any character, please use the image  '[./n]'  The model.
(pattern)  matching pattern  And get it 1 Matching.
(?:pattern)  matching pattern  But it doesn't get a match, which means that this is 1 Non - retrieve matches, not stored for later use.
(?=pattern)  Forward preview in any match  pattern  Matches the lookup string at the beginning of the string. This is a 1 Six non-fetch matches, that is, the match does not need to be fetched for later use.
(?!pattern)  Negative preview, and (?=pattern) opposite
x|y  matching  x  or  y .
[xyz]  Character set.
[^xyz]  A collection of negative characters.
[a-z]  Character range that matches any character in the specified range.
[^a-z]  A negative character range that matches any character that is not in the specified range.
/b  matching 1 The word boundary is the position between the word and the space.
/B  Matches non-word boundaries.
/cx  Matched by x The specified control character.
/d  matching 1 Two numeric characters. Is equivalent to  [0-9] .
/D  matching 1 Non - numeric characters. Is equivalent to  [^0-9] .
/f  matching 1 Page break. Is equivalent to  /x0c  and  /cL .
/n  matching 1 A newline character. Is equivalent to  /x0a  and  /cJ .
/r  matching 1 A carriage return. Is equivalent to  /x0d  and  /cM .
/s  Matches any whitespace character, including Spaces, tabs, page breaks, and so on. Is equivalent to [ /f/n/r/t/v] .
/S  Matches any non-white space characters. Is equivalent to  [^ /f/n/r/t/v] .
/t  matching 1 Six tabs. Is equivalent to  /x09  and  /cI .
/v  matching 1 Vertical tabs. Is equivalent to  /x0b  and  /cK .
/w  Matches any word character that includes an underscore. Is equivalent to '[A-Za-z0-9_]' .
/W  Matches any non-word character. Is equivalent to  '[^A-Za-z0-9_]' .
/xn  matching  n , including  n  for 106 Base escape value. 106 The base escape value must be two digits long.
/num  matching  num , including num is 1 Positive integers. A reference to the obtained match.
/n  logo 1 a 8 Base escape value or 1 Ten backward references. if  /n  At least before  n  Is the obtained subexpression  n  Is a backward reference. Otherwise, if  n  for 8 Hexadecimal Numbers  (0-7) ,  n  for 1 a 8 Base escape value.
/nm  logo 1 a 8 Base escape value or 1 Ten backward references. if  /nm  At least before is preceded by at least nm  Can obtain a subexpression, then  nm  Is a backward reference. if  /nm  At least before  n  Get, then  n  for 1 Followed by text  m  Is a backward reference. If none of the previous conditions are met, if  n  and  m  Are all 8 Hexadecimal Numbers  (0-7) ,  /nm  Will match 8 Base escape value  nm .
/nml  if  n  for 8 Hexadecimal Numbers  (0-3) And,  m  and  l  Are all 8 Hexadecimal Numbers  (0-7) , the match 8 Base escape value  nml .
/un  matching  n , including  n  is 1 with 4 a 106 In base Numbers Unicode Characters.
Regular expressions matching Chinese characters:  [u4e00-u9fa5]
Matches double-byte characters ( Including Chinese characters ) : [^x00-xff]
A regular expression matching an empty line: n[s| ]*r
matching HTML Regular expressions for tags: /<(.*)>.*</1>|<(.*) />/
A regular expression matching Spaces at the beginning and end: (^s*)|(s*\$)
matching Email Regular expression of address: w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
Match the url URL Is the regular expression of: http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?
Use regular expressions to restrict what can be entered in a text box on a web form:
With regular expression restriction, only Chinese can be entered: onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))"
Use regular expressions to restrict entry to only full-angle characters:  onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))"
Use regular expressions to restrict entry to only Numbers: onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"
Use regular expressions to restrict entry to only Numbers and English: onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"
========= Common regular expression

Regular expressions matching Chinese characters:  [/u4e00-/u9fa5]
Matches double-byte characters ( Including Chinese characters ) : [^/x00-/xff]
A regular expression matching an empty line: /n[/s| ]*/r
matching HTML Regular expressions for tags: /<(.*)>.*<///1>|<(.*) //>/
A regular expression matching Spaces at the beginning and end: (^/s*)|(/s*\$)
matching IP Regular expression of address: /(/d+)/.(/d+)/.(/d+)/.(/d+)/g //
matching Email Regular expression of address: /w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
Match the url URL Is the regular expression of: http://(/[/w-]+/.)+[/w-]+(/[/w- ./?%&=]*)?
sql Statement: ^(select|drop|delete|create|update|insert).*\$
1 , non-negative integers: ^/d+\$
2 , positive integers: ^[0-9]*[1-9][0-9]*\$
3 , non-positive integers: ^((-/d+)|(0+))\$
4 , negative integers: ^-[0-9]*[1-9][0-9]*\$
5 , integer: ^-?/d+\$
6 , non-negative floating point number: ^/d+(/./d+)?\$
7 , positive floating point number: ^((0-9)+/.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*/.[0-9]+)|([0-9]*[1-9][0-9]*))\$
8 , non-positive floating point number: ^((-/d+/./d+)?)|(0+(/.0+)?))\$
9 , negative floating point number: ^(-(( Regular expressions of positive floating point Numbers )))\$
10 , English string: ^[A-Za-z]+\$
11 , English capital string: ^[A-Z]+\$
12 , English lowercase string: ^[a-z]+\$
13 , English characters and Numbers: ^[A-Za-z0-9]+\$
14 , English numerals and underscore strings: ^/w+\$
16 , URL : ^[a-zA-Z]+://(/w+(-/w+)*)(/.(/w+(-/w+)*))*(/?/s*)?\$
Or: ^http:////[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^<>/"/"])*\$
17 , Postal code: ^[1-9]/d{5}\$
18 And Chinese: ^[/u0391-/uFFE5]+\$
19 , Telephone number: ^((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?\$
20 , Mobile phone Number: ^((/(/d{2,3}/))|(/d{3}/-))?13/d{9}\$
21 , double byte characters ( Including Chinese characters ) : ^/x00-/xff
22 , match the first and last Spaces: (^/s*)|(/s*\$) (like vbscript That kind of trim Function)
23 , match, HTML Tags: <(.*)>.*<///1>|<(.*) //>
24 , match blank lines: /n[/s| ]*/r
25 , network links extracted from information: (h|H)(r|R)(e|E)(f|F) *= *('|")?(/w|//|//|/.)+('|"| *|>)?
26 , extract the email address in the information: /w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
27 , link to pictures extracted from information: (s|S)(r|R)(c|C) *= *('|")?(/w|//|//|/.)+('|"| *|>)?
28 , to extract information IP Address: (/d+)/.(/d+)/.(/d+)/.(/d+)
29 , Extract the Chinese mobile phone number in the information: (86)*0*13/d{9}
30 , Chinese fixed telephone number extracted from the information: (/(/d{3,4}/)|/d{3,4}-|/s)?/d{8}
31 , extract the Chinese telephone number in the information (including mobile and fixed telephone) : (/(/d{3,4}/)|/d{3,4}-|/s)?/d{7,14}
32 , The Chinese postal code in the extracted information: [1-9]{1}(/d+){5}
33 , floating-point Numbers (i.e., decimals) in information extraction: (-?/d*)/.?/d+
34 , extract any number in the information   : (-?/d*)(/./d+)?
35 , IP : (/d+)/.(/d+)/.(/d+)/.(/d+)
36 Area code: /^0/d{2,3}\$/
37 , tencent QQ No. : ^[1-9]*[1-9][0-9]*\$
38 , account ( The letter begins, allow 5-16 Byte, allowing alphanumeric underscore ) : ^[a-zA-Z][a-zA-Z0-9_]{4,15}\$
39 , Chinese, English, numerals and underscores: ^[/u4e00-/u9fa5_a-zA-Z0-9]+\$
``````

Related articles: