PHP regular expression commonly used example

"^ [0-9] * [1-9] [0-9] * $" // positive integer "^ ((- \ d + ) | (0 +)) $" // non-positive integer (negative integer + 0) "^ - [0-9] * [1-9] [0-9] * $" // negative integer "^ -? \ d + $ " // integer "^ \ d + (\ \ d +).? $ "// non-negative floating-point numbers (positive float 0 +) " ^ (([0-9] + \ [0-9] * [1-9] [0-9] *) |. ([0- 9] * [1-9] [0-9 ] * \ [0-9] +) |. ([0-9] * [1-9] [0-9] *)) $ "// upright points "^ ((- \ d + (\ \ d +)) |.?.? (0 + (\ 0 +))) $" // non-positive float (negative float + 0) "^ (- (( [0-9] + \ [0-9] * [1-9] [0-9] *) |. ([0-9] * [1-9] [0-9] * \ [0-. 9] +) | ([0-9 ] * [1-9] [0-9] *))) $ "// negative float " ^ (- \ d +) (\ \ d +) $ "?.? // float "^ [a-Za-z ] + $" // string consisting of the 26 English letters "^ [AZ] + $" // string of uppercase letters 26 composed of "^ [az] + $ "// string of 26 lowercase letters consisting of " ^ [a-Za-z0-9 ] + $ "// string of numbers and English letters 26 " ^ \ w + $ "// string of digits, letters or underscore 26 consisting of "^ [\ w -] + (. \ [\ W -] +) * @ [\ w -]. + (\ [\ W -] + ) + $ "// email address 
 
 
 


 

 
 
 
 
 
 
 
 
"^ [a-zA-z ] +: // (\ w + (- \ w +) *) (\ (\ w + (- \ w +) *).) * (\ \ S *?) $?" // URL / ^ (2 {D} | {D}. 4) - ((0 ([1-9] {}. 1)) | (. 1 [. 1 | 2])) - (([0-2] ([. 1 -9] {1})) | (3 [0 | 1])) $ / // - in - day / ^ ((0 ([1-9 ] {1})) | (1 [1 | 2 ])) / (([0-2 ] ([1-9] {1})) | (3 [0 | 1])) / (d {2} | d {4}) $ / // month / day / year "^ ([w -.] +) @ (([[0-9] {1,3} [0-9] {1,3} [0-9] {1,3}... ) | (. ([W -] +) +)) ([A-zA-the Z] {2,4} | [0-9] {l, 3}) (]) $ "of Emil //? / ^ ((\ + [0-9] { 2,4} \ - [0-9] {3,4} \ -) |? ([0-9] {3,4} \ -)) ([0? -9] {7,8}) (\ - [0-9] +) $ / // phone number? "^ (D {1,2} | 1DD | 2 [0-4] D | 25 [0- 5]) (d {1,2} |. 1dd | 2 [0-4] d | 25 [0-5]) (d {1,2} |. 1dd | 2 [0-4] d | 25 [ . 0-5]) (d {1,2 } | 1dd | 2 [0-4] d | 25 [0-5]) $ "// IP address matching Chinese characters regular expression: [\ u4e00- \ u9fa5] matching double-byte characters (including characters included): [^ \ x00- \ xff ] matches the regular expression blank line: \ n [\ s |] * \ r match the regular expression HTML tags: / < (. *). | (. *)> * <\ / \ 1> <\ /> / match trailing spaces regular expression: (^ \ s *) | (\ s * $) 
 
 
 
 



 
 
 
 
 
Matching Email address regular expression:. \ W + ([- . +] \ W +) * @ \ w + ([-.] \ W +) * \ \ w + ([-.] \ W +) * matches at URL regular expression: ^ [a-zA-z ] +: // (\\ w + (- \\ w +) *) (\\ (\\ w + (- \\ w +) *).) * (\\ \? ? \ S *) $ matches the account is valid (starting with the letter, allowing 5-16 bytes to allow alphanumeric underlined): ^ [a-zA- Z] [a-zA-Z0-9 _] {4,15} $ domestic matching telephone number:?? (\ d {3 } - | \ d {4} -) (\ d {8} | \ d {7}) matching Tencent QQ: ^ [1-9] * [1- 9] [0-9] * $ use regular expressions to limit web form in the text box to enter the content: use regular expressions to limit only enter Chinese: onkeyup = "value = value.replace ( / [^ u4E00-u9FA5] / g, '') "onbeforepaste = " clipboardData.setData ( 'text', clipboardData.getData ( 'text'). replace (/ [^ u4E00-u9FA5] / g, '')) " regular expression can limit enter the full-size character:. onkeyup = "value = value.replace (/ [^ uFF00-uFFFF] / g, '')" onbeforepaste = "clipboardData.setData ( 'text', clipboardData.getData ( 'text') replace (/ [^ uFF00-uFFFF] / g , '')) " 
 
 
 


 
 
 

As a regular expression can limit the input digital: onkeyup = "value = value.replace ( / [^ d] / g, '')" onbeforepaste = "clipboardData.setData ( 'text', clipboardData.getData ( 'text') .replace (/ [^ d] / g, '')) "

regular expression restricted only numbers and English: onkeyup =" value = value.replace ( / [W] / g, '') "onbeforepaste = "clipboardData.setData ( 'text', clipboardData.getData ( 'text'). Replace (/ [^ D] / G, ''))"


========= conventional regular expression

matching Chinese characters in it expression: [\ u4e00- \ u9fa5] matching double-byte characters (including Chinese characters included): [^ \ x00- \ xff ] matches the empty rows of regular expression: \ n [\ s |] * \ r matching HTML tag regular expression:. / <(. *) > * <\ / \ 1> | <(. *) \ /> / matching trailing spaces regular expression: (^ \ s *) | (\ s * $) . the matching IP address regular expression: / (\ d +) \ (\ d +) \ (\ d +) \ (\ d +) / g // matching Email address regular expression: \ w + ([- .... +] \ w +) * @ \ w + ([-] \ w +) * \ \ w + ([-] \ w +) * matches at URL regular expression: http: // (/ [\ w- ] + \) + [\ w -.] + (/ [\ w-.? / =% &] *)? SQL statement:. ^ (Select | drop | delete | create | update | insert) * $ non-negative integers: ^ \ d + $ 
 
 
 
 
 
 
 


 
Positive integer: ^ [0-9] * [1-9] [0-9] * $ non-positive integer: ^ ((- \ d + ) | (0 +)) $ negative integers: ^ - [0-9] * [1-9] [0-9] * $ integer: ^ - \ d + $? non-negative floating-point numbers:? ^ \ d + (. \ \ d +) $ positive float: ^ ((0-9) + \ . [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \ [0-9] +) |. ([ 0-9] * [1-9] [0-9] *)) $ non-positive float:.?. ^ ((- \ d + \ \ d +)) | (0 + (\ 0+)))? $ negative float: ^ (- ((positive float regular formula))) $ English string: ^ [A-Za-z ] + $ capital string: ^ [AZ] + $ lowercase string: ^ [AZ ] + $ English character numeric string: ^ [A-Za-z0-9 ] + $ alphanumeric string is underlined: ^ \ $ W + E-mail address:. ^ [\ w -] + (\ [\ w-] +) * @ [\ w -] + (. \ [\ w -] +) + $ the URL of: ^ [A-zA-the Z-] +: // (\ w + (- \ w +) *) (\ (. ? \ w + (- \ w +) *)) * (\ \ s *) $ or: ^ http: \ / \ / [A-Za-z0-9] + \ [A-Za-z0-9]?. + [\ / = \% \ - `~ @ & _ [\] \ ':?! +] * ([^ <> \" \ "]) * $ ZIP: ^ [1-9] \ d { 5 } $ Chinese: ^ [\ u0391- \ uFFE5] + $ telephone number:? ^ ((\ (\ d {2,3} \)) | (\ d {3} \ -)) (\ (0 \ d {2,3} \) |? 0 \ d {2,3} -) [1-9] \ d {6,7} (\ - \ d {1,4}) $? 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Phone number: ^ ((\ (\ d {2,3} \)) | (\ d {3} \ -)) 13 \ d {9} $? Double-byte characters (including Chinese characters included): ^ \ x00- \ xff match both spaces: (^ \ s *) | (\ s * $) ( as trim function as vbscript) matching HTML tags: * <\ / \ 1> | <(<(*.)>. . *) \ /> match blank line: \ n [\ s |] * \ r extract the network link information: (h | H) (r | R) (e | E) (f | F) * = * ? ( '| ")? ( . \ w | \\ | \ / | \) + (' |" | * |>) to extract e-mail address information: \ w + ([- + .] \ w +) * @ . \ w + ([-. ] \ w +) * \ \ w + ([-.] \ w +) * extracts image link information: (s | S) (r | R) (c | C) * = * ( '| ") (\ w | \\ | \ / | \) + (?.' |" | * |>)? extracts the IP address information: (\ d +) \ ( \ d +) \ (\.. . d +) \ (\ d +) extracting information in China's mobile phone number: (86) * 0 * 13 \ d {9} extract information in China's fixed telephone number: (\ (\ d {3,4 } \) | ? \ d {3,4} - | \ s) \ d {8} extracts the telephone number information in China (including mobile and fixed phones): (\ (\ d { 3,4} \) | \ d {3 ?, 4} - | \ s ) \ d {7,14} extract information in China ZIP: [1-9] {1} ( \ d +) {5} to extract information in floating-point (i.e. decimals): .? (-? \ d * ) \ \ d + extract any digital information: (- \ d *?) (\ \ d +.) IP: (\ d +) \ (\ d +) \ (\ d +?.. ) \.(\ d +) Telephone area code: / ^ 0 \ d {2,3 } $ / 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
Tencent QQ: ^ [1-9] * [1-9] [0-9] * $ account (beginning with the letter, allowing 5-16 bytes to allow alphanumeric underlined): ^ [A-zA-the Z] [ a-zA-Z0-9 _] { 4,15} $ Chinese, English, numbers and underscores: ^ [\ u4e00- \ u9fa5_a- zA-Z0-9] + $ 

 
 

Guess you like

Origin www.cnblogs.com/chenduzizhong/p/11137745.html