This section describes some common regular expressions, such as regular expression verification of date, number, phone number, and time format.
Regular Expression Matching Chinese characters: [u4e00-u9fa5]
Note: matching Chinese characters is really a headache. It is easy to use this expression.
Match double byte characters (including Chinese characters): [^ x00-xff]
Comment: It can be used to calculate the length of a string (a dual-byte length meter 2, ASCII character meter 1)
Regular Expression Matching blank rows: ns * r
Comment: It can be used to delete blank rows.
Regular expressions matching HTML tags: <(S *?) [^>] *> .*? </1> & brvbar; <.*? />
Comments: The versions circulating on the Internet are too bad. The above can only match some of them, and there is still nothing to do with complicated nested tags.
Regular expression matching the first and last blank characters: ^ s * & brvbar; s * $
Comments: It can be used to delete spaces (including spaces, tabs, page breaks, and so on) at the beginning and end of a line. It is a very useful expression.
Regular Expression Matching the Email address: w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w + )*
Comment: form verification is very useful
Regular Expression Matching URL: [a-zA-z] +: // [^ s] *
Comments: versions circulating on the Internet have limited functions. The above can basically meet the requirements.
Match account validity (starting with a letter, may be 5-16 bytes, may be an alphanumeric underline): ^ [a-zA-Z] [a-zA-Z0-9 _] {} $
Comment: form verification is very useful
Match Chinese phone number: d {3}-d {8} & brvbar; d {4}-d {7}
Commentary: matching forms such as 0511-4405222 or 021-87888822
Match Tencent QQ number: [1-9] [0-9] {4 ,}
Comment: Tencent QQ number starts from 10000
Match China Zip code: [1-9] d {5 }(?! D)
Note: China post code is a six-digit number.
Matched ID card: d {15} & brvbar; d {18}
Note: the ID card of China is 15 or 18 characters
Matched IP address: d +. d +
Comments: useful when extracting IP addresses
Match a specific number:
^ [1-9] d * $ // match a positive integer
^-[1-9] d * $ // match a negative integer
^ -? [1-9] d * $ // match the integer
^ [1-9] d * & brvbar; 0 $ // match a non-negative integer (positive integer + 0)
^-[1-9] d * & brvbar; 0 $ // Match non-positive integers (negative integers + 0)
^ [1-9] d *. d * & brvbar; 0. d * [1-9] d * $ // match the positive floating point number
^-([1-9] d *. d * & brvbar; 0. d * [1-9] d *) $ // match the negative floating point number
^ -? ([1-9] d *. d * & brvbar; 0. d * [1-9] d * & brvbar; 0 ?. 0 + & brvbar; 0) $ // Match floating point number
^ [1-9] d *. d * & brvbar; 0. d * [1-9] d * & brvbar; 0 ?. 0 + & brvbar; 0 $ // Match non-negative floating point number (positive floating point number + 0)
^ (-([1-9] d *. d * & brvbar; 0. d * [1-9] d *) & brvbar; 0 ?. 0 + & brvbar; 0 $ // Match non-positive floating point number (negative floating point number + 0)
Comments: It is useful when processing large amounts of data. Pay attention to correction when handling specific applications.
Match a specific string:
^ [A-Za-z] + $ // match A string consisting of 26 English letters
^ [A-Z] + $ // match a string consisting of 26 uppercase letters
^ [A-z] + $ // match a string consisting of 26 lowercase letters
^ [A-Za-z0-9] + $ // match a string consisting of digits and 26 letters
^ W + $ // match a string consisting of digits, 26 English letters, or underscores