Common regular expression

xiaoxiao2021-03-06  80

Some commonly used regular expressions: (Perl compatible)

Domestic phone number: // (? (/ D {3, 4})? /)? / -? (/ D) {7,8} / x domestic mobile number: / 13 (0 | 1 | 3 | 5 | 6 | 7 | 8 | 9) {1} (/ d) {8} / email code: / (/ d) {6} / email address: / [_ /. 0-9a-z -] @ ( [0-9A-Z] /.) [AZ] {2, 3} / i Date (Day Month): / ((19) | (20))? (/ d) {2} (- | //) {1} (0 | 1)? (/ d) {1} (- | //) {1} [0-3] {1} (/ d) {1 } / (Not very accurate, there is no judgment and number of days) page hyperlink: / ] *? Href [/ s] = [/ s / "/ '] (. *?) [/ "/'] . * ?> ([^<] |. *?)? / is

The following from: http://www.oioj.net/blog/new3/zan0000/archives/2006/261324.SHTML has not been tested.

Regular expressions matching Chinese characters: [/ u4e00- / u9fa5] comment: Matching Chinese is really a headache, with this expression is good to match the double-byte character (including Chinese characters): [^ / X00- / XFF] Comment: Can be used to calculate the length of the string (a double byte character length 2, ASCII characters 1) Match the regular expression of the blank line: / n / s * / r Comments: can be used Deleting a blank line matches the regular expression of the HTML tag: <(/ s *?) [^>] *>. *? | <. *? /> Comment: The version of the Internet is too bad, and this is only matching the part. For complex nested markers still incompetently picked the regular expression of the first tail blank character: ^ / s * | / s * $ comment: Can be used to remove blank characters at the end of the row (including spaces, tabs, change Variety, etc.), very useful expressions match the regular expression of the Email address: / w ([- .] / W ) * @ / w ([-.] / W ) * /. / W . ] / w ) * Comment: Form verification Very practical matching URL regular expression: [A-ZA-Z] : // [^ / s] * Comment: The version of the version is limited, the above Can meet the needs matching account is legal (the start of the letter, allowing 5-16 bytes, allowing alphanumeric data Underline): ^ [A-ZA-Z] [A-ZA-Z0-9 _] {4,15} $ comment: Form Very practicality matches domestic telephone number: / d {3} - / d {8} | / d {4} - / d {7} Comment: Matching form, such as 0511-4405222 or 021-87888822 match Tencent QQ number: [ 1-9] [0-9] {4,} Comment: Tencent QQ number starts to match China Postal Code from 10000: [1-9] / D {5} (?! / D) Comments: China Postal Code is 6 Digital match ID card: / d {15} | / d {18} Comment: China's ID card is 15 or 18-bit match IP address: / d /. / D /. / D /. / D comment: Extract IP Useful matching specific numbers: ^ [1-9] / d * $ // Match positive integer ^ - [1-9] / d * $ // Matching negative integers ^ -? [1-9] / d * $ // Match an integer ^ [1-9] / d * | 0 $ // Match non-negative integer (positive integer 0) ^ - [1-9] / d * | 0 $ // Matching non-positive integer (negative integer 0) ^ [1-9] / d * /. / D * | 0 /. D * [1-9] / d * $ // Match positive floating point number ^ - ([1-9] / d * /./d*| 0. .) ^ 负 负 负浮 ^ -? ([1-9] / d * /. / d * | 0 /. D * [1-9] / d * | 0? /. 0 | 0) $ // Match floating point ^ [1-9] / d * /. / d * | 0 /. D * [1-9] / d * | 0? /. 0 | 0 $ // Match the number of non-looted points (positive floating point 0) ^ (- ([ 1-9] / d * /. / D * | 0 /. D * [1-9] / d *)) | 0? /. 0 | 0 $ // Match non-positive floating point numbers (lung float 0) Comment: Use when working with large amounts of data, pay attention to correcting matching specific strings when specific applications: ^ [a-za-z] $ // Matching strings consisting of 26 English letters ^ [AZ] $ / / Match string ^ [AZ] $ // composed of 26 English letters, matching string ^ [A-ZA-Z0-9] $ // matches the number of 26 English letters And 26 English letters consisting of strings ^ / w

$ // Matching strings of numbers, 26 English letters, or underscore /< (. ) (. ?) <所有 所有 所有 字 字 字 字 字 字 字 字 字String content.


New Post(0)