Regular expressions for string processing, form verification, and other occasions, practical and efficient. Some commonly used expressions are collected here to prepare for a rainy-future. Article reproduced from: http://www.phpchina.com/31423/viewspace_9417.html
a regular expression that matches a Chinese character:[\u4e00-\u9fa5]
Commentary: Matching Chinese is really a headache, with this expression will be easy to do
match Double-byte characters (including Chinese characters):[^\x00-\xff]
Commentary: can be used to compute the length of a string (a double-byte character length meter 2,ascii 1 characters)
a regular expression that matches a blank row:\n\s*\r
Commentary: can be used to delete blank lines
a regular expression that matches an HTML tag:< (\s*?) [^>]*>.*?</\1>|<.*? />
Commentary: The online version is too bad, the above can only match the part of the complex nested tags still powerless
a regular expression that matches the trailing-end whitespace character:^\s*|\s*$
Commentary: A useful expression that can be used to delete white-space characters (including spaces, tabs, page breaks, and so on) at the end of a line at the beginning
Regular expression matching an email address:\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
Commentary: Form validation is useful
a regular expression that matches the URL of the URL:[a-za-z]+://[^\s]*
Commentary: Online circulation of the version of the function is very limited, which can meet the basic requirements
Match account number is legal (beginning of letter, allow 5-16 bytes, allow alphanumeric underline):^[a-za-z][a-za-z0-9_]{4,15}$
Commentary: Form validation is useful
Match Domestic phone number:\D{3}-\D{8}|\D{4}-\D{7}
Commentary: Match form such as 0511-4405222 or 021-87888822
matching Tencent QQ number:[1-9] [0-9] {4,}
Commentary: Tencent QQ number starting from 10000
match China zip code:[1-9]\d{5} (?! \d)
Commentary: China postal code is 6 digits
Matching ID:\D{15}|\D{18}
Commentary: China's ID card is 15-or 18-digit
Match IP Address:\d+\.\d+\.\d+\.\d+
Commentary: Useful when extracting IP addresses
match a specific number:
^[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)
Commentary: useful when dealing with large amounts of data, pay attention to corrections when applied
match a specific string:
^[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
Commentary: Some of the most basic and commonly used expressions
Introduction to Regular Presentations: http://soft.yesky.com/lesson/211/2350711.shtml