The following are a large number of common php regular expression rules. If you do not understand them, refer to this article to quickly implement php regular expressions. For more information, see. The following are a large number of common php regular expression rules. If you do not understand them, refer to this article to quickly implement php regular expressions. For more information, see.
Script ec (2); script
Let's take a look at the specific application of the regular expression metacharacters.
/Fo +/
Because the above regular expression contains the "+" metacharacter, it can be used with the "fool", "fo ", or "football", and so on, one or more character strings that match the letter "f" consecutively.
/Eg */
Because the above regular expression contains the "*" metacharacter, it can be used with the "easy", "ego ", or, "egg" and other strings that appear after the letter e are matched with zero or multiple Letter g consecutively.
/Wil? /
Because the above regular expression contains "?" Metacharacter, indicating that it can match the "Win" or "Wilson" in the target object, and matches zero or one character string after the letter I.
In addition to metacharacters, you can also precisely specify the frequency of occurrence of a pattern in a matching object. For example,
/Jim {2, 6 }/
The above regular expression specifies that the character m can appear 2-6 times consecutively in the matching object. Therefore, the above regular expression can match strings such as jimmy or jimmm.pdf.
After a preliminary understanding of how to use regular expressions, let's take a look at the usage of several other important metacharacters.
S: Used to match a single space character, including the tab key and line break;
S: Used to match all characters except a single space character;
D: Used to match numbers from 0 to 9;
W: Used to match letters, numbers, or underscores;
W: Used to match all characters that do not match w;
.: Used to match all characters except line breaks.
(Note: we can regard s and S and w and W as inverse operations)
Next, let's take a look at how to use the above metacharacters in regular expressions through examples.
/S +/
The above regular expression can be used to match one or more space characters in the target object.
/D000/
"^ D + $" // non-negative integer (positive integer + 0)
"^ [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 number (Positive floating point number + 0)
"^ ([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// Positive floating point number
"^ (-D + (. d + )?) | (0 + (. 0 + )?)) $ "// Non-Positive floating point number (negative floating point number + 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
Quantity
"^ (-? D +) (. d + )? $ "// Floating point number
"^ [A-Za-z] + $" // A string consisting of 26 English letters
"^ [A-Z] + $" // a string consisting of 26 uppercase letters
"^ [A-z] + $" // a string consisting of 26 lowercase letters
"^ [A-Za-z0-9] + $" // string consisting of digits and 26 letters
"^ W + $" // a string consisting of digits, 26 letters, or underscores
"^ [W-] + (. [w-] +) * @ [w-] + (. [w-] +) + $" // email address
"^ [A-zA-z] +: // (w + (-w +) *) (. (w + (-w + )*))*(? S *)? $ "// Url
Regular Expression -- verify mobile phone number: 13 [0-9] {9}
If the mobile phone number is 86 or + 86 before it is implemented: ^ (+ 86) | (86 ))? (13) d {9} $
Verify the phone number and phone number at the same time: (^ (d {3, 4 }-)? D {7,8}) $ | (13 [0-9] {9 })
Extract the network link in the information: (h | H) (r | R) (e | E) (f | F) * = * ('| ")? (W | \ |/|.) + ('| "| * |> )?
Email Address in the extracted information: w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w + )*
Extract the image link in the information: (s | S) (r | R) (c | C) * = * ('| ")? (W | \ |/|.) + ('| "| * |> )?
Extract the IP address in the information: (d +). (d +)
Extract the Chinese mobile phone number from the information: (86) * 0 * 13d {9}
Extracted Chinese landline numbers: (d {3, 4}) | d {3, 4}-| s )? D {8}
Extract Chinese phone numbers (including mobile and landline phones) from the Information: (d {3, 4}) | d {3, 4}-| s )? D {7, 14}
Extracted Chinese zip code: [1-9] {1} (d +) {5}
Extracted Chinese ID card number: d {18} | d {15}
Extract the integer in the information: d +
Extract floating point numbers (decimal places) in the Information ):(-? D *).? D +
Extract any number from the information :(-? D *) (. d + )?
Extract Chinese strings from information: [u4e00-u9fa5] *
Double Byte string in extracted information (Chinese character): [^ x00-xff] *