Regular expressions _ regular expressions commonly used in the collection and collation of an item

Source: Internet
Author: User
Tags html tags

Recently done an internal system project, involving a large number of text validation, which used a number of commonly used regular expressions, collection is not easy, first recorded here, for later use.

Matching regular expressions for Chinese characters: [\U4E00-\U9FA5]

Match Double-byte characters (including Chinese characters): [^\x00-\xff] can be used to compute the length of a string (a double-byte character length meter 2,ascii 1)

Regular expression matching blank rows: \n\s*\r can be used to delete blank lines

Regular expression:< matching HTML tags (\s*?) [^>]*>.*?| < *? /> This can only match the part, there is still nothing for complex nested tags

A regular expression that matches the last and last whitespace character: ^\s*|\s*$ can be used to delete white space characters (including spaces, tabs, page breaks, and so on) at the end of a line, very useful expressions

Regular expression matching an email address: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * Form verification is practical

A regular expression that matches the URL of the URL: [a-za-z]+://[^\s]* this basic to meet the requirements

Match account number is legal (start of letter, allow 5-16 bytes, allow alphanumeric underline) ^[a-za-z][a-za-z0-9_]{4,15}$ form validation is useful

Match domestic phone number: \d{3}-\d{8}|\d{4}-\d{7} match form such as 0511-4405222 or 021-87888822

Matching Tencent QQ Number: [1-9][0-9]{4,} Tencent QQ number starting from 10000

Match China ZIP Code: [1-9]\d{5} (?! \d) China postal Code is 6 digits

Matching ID: \d{15}|\d{18} China's ID card is 15-digit or 18-digit number (excluding X)

^\d*\.? [0-9]\d*$//matching digits (including decimals)
^[1-9]\d*$//Matching positive integer
^-[1-9]\d*$//matching negative integers
^-? [1-9]\d*$//matching integer
^[1-9]\d*|0$//matching nonnegative integer (positive integer + 0)
^-[1-9]\d*|0$//matching non positive integer (negative integer + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$//matching positive floating-point numbers
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*) $//matching negative floating-point number
^-? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0) $//matching floating-point number
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$//matching nonnegative floating-point number (positive floating-point number + 0)
^ (-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)) |0?\.0+|0$//matching non-positive floating-point numbers (negative floating-point number + 0)
^[a-za-z]+$//Match a string of 26 English letters
^[a-z]+$//Match a string of 26 uppercase letters
^[a-z]+$//Match string consisting of 26 lowercase letters
^[a-za-z0-9]+$//Match a string of numbers and 26 English letters
^\w+$//Match A string of numbers, 26 English letters, or underscores

The following is actually a code fragment of an enumeration class, I am a bit lazy, do not do meticulous finishing:

The regular expression of/** scientific counting method * *

Regex_scien ("^" (\\d+. \\d+) [Ee]{1} (\\d+)) $ "," scientific notation Regular expression "),

/** Mobile phone number verification regular expression * *

Regex_mobile ("^1 (3|5|8) [0-9]{9}$", "mobile number validation Regular expression"),

/** amount Format Regular Expression * *

Regex_amount ("^[-]?[ \\d]{1,10} ([.] {1} [\\d] {1,2})? $ "," amount format Regular expression "),

/**-YYYYMM Regular Expression * *

Regex_month ("^" [1-9]\\d{3}) ([0][1-9]) | ( [1] [0-2])) $ "," yyyymm Regular expression "),

/** YYYYMMDD Date format Regular Expression * *

Regex_date (
"([0-9]{3}[1-9]| [0-9] {2} [1-9] [0-9] {1}| [0-9] {1} [1-9] [0-9] {2}| [1-9] [0-9] {3}) (((0[13578]|1[02]) (0[1-9]|[ 12][0-9]|3[01]) | ((0[469]|11) (0[1-9]|[ 12][0-9]|30)) | (02 (0[1-9]|[ 1][0-9]|2[0-8])) | (([0-9]{2}) (0[48]|[ 2468][048]| [13579] [26]) | ((0[48]| [2468] [048]| [3579] [26]) 00)) 0229) ",
"YYYYMMDD date format Regular expression"),

/** Email Verification Regular expression * *

Regex_email (
"^ ([_\\w-\\.] +) @ (\\[[0-9]{1,3}\\. [0-9] {1,3}\\. [0-9] {1,3}\\.) | (([_\\w-]+\\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\\]?)) $",
"Email verification of regular expression");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.