Common Front-end regular expressions

Source: Internet
Author: User
Tags control characters
Expression Complete Set
Character Description
\ Mark the next character as a special character, a literal character, or a backward reference, or an octal escape character. For example,n"Matching character"n". "\nMatch a line break. Serial"\\"Match"\"And"\("Matches"(".
^ Matches the start position of the input string. If the multiline attribute of the Regexp object is set, ^ matches"\n"Or"\r.
$ Matches the end position of the input string. If the multiline attribute of the Regexp object is set, $ also matches"\n"Or"\r.
* Matches the previous subexpression zero or multiple times. For example, Zo * can match"z"And"zoo". * Is equivalent to {0 ,}.
+ Match the previous subexpression once or multiple times. For example,zo+"Can match"zo"And"zoo", But cannot match"z". + Is equivalent to {1 ,}.
? Match the previous subexpression zero or once. For example,do(es)?"Can match"does"Or"does"In"do".? It is equivalent to {0, 1 }.
{N} N is a non-negative integer. Match n times. For example,o{2}"Cannot match"Bob"In"o", But can match"food.
{N ,} N is a non-negative integer. Match at least N times. For example,o{2,}"Cannot match"Bob"In"o", But can match"foooood. "o{1,}"Is equivalent to"o+". "o{0,}"Is equivalent to"o*".
{N, m} Both m and n are non-negative integers, where n <= m. Match at least N times and at most m times. For example,o{1,3}"Will match"fooooood. "o{0,1}"Is equivalent to"o?". Note that there must be no space between a comma and two numbers.
? When this character is followed by any other delimiter (*, + ,?, The matching mode after {n}, {n ,}, {n, m}) is not greedy. The non-Greedy mode matches as few searched strings as possible, while the default greedy mode matches as many searched strings as possible. For example,oooo","o+?"Will match a single"o", And"o+"Will match all"o".
. Match the\n. To match the\n", Please use any character like"(.|\n).
(Pattern) Match pattern and obtain this match. The obtained match can be obtained from the generated matches set. The submatches set is used in VBScript, and $0… is used in JScript... $9 attribute. To match the parentheses, use the"\("Or"\)".
(? : Pattern) Matches pattern but does not get the matching result. That is to say, this is a non-get match and is not stored for future use. This is in use or the character"(|)It is very useful to combine all parts of a pattern. For example,industr(?:y|ies)"Is a comparison"industry|industries"A simpler expression.
(? = Pattern) Forward validation pre-query: matches the search string at the beginning of any string that matches pattern. This is a non-get match, that is, the match does not need to be obtained for future use. For example,Windows(?=95|98|NT|2000)"Can match"Windows2000"In"Windows", But cannot match"Windows3.1"In"Windows". Pre-query does not consume characters, that is, after a match occurs, the next matching search starts immediately after the last match, instead of starting after the pre-query characters.
(?! Pattern) Forward negative pre-query: matches the search string at the beginning of any string that does not match pattern. This is a non-get match, that is, the match does not need to be obtained for future use. For example,Windows(?!95|98|NT|2000)"Can match"Windows3.1"In"Windows", But cannot match"Windows2000"In"Windows". Pre-query does not consume characters. That is to say, after a match occurs, the next matching search starts immediately after the last match, instead of starting after the pre-query characters.
(? <= Pattern) The reverse direction is certainly precheck, which is similar to the forward positive direction. For example,(?<=95|98|NT|2000)Windows"Can match"2000Windows"In"Windows", But cannot match"3.1Windows"In"Windows".
(? <! Pattern) Reverse negative pre-query, similar to forward negative pre-query, is in the opposite direction. For example,(?<!95|98|NT|2000)Windows"Can match"3.1Windows"In"Windows", But cannot match"2000Windows"In"Windows".
X | y Match X or Y. For example,z|food"Can match"z"Or"food". "(z|f)ood"Matches"zood"Or"food".
[Xyz] Character Set combination. Match any character in it. For example,[abc]"Can match"plain"In"a".
[^ XYZ] Negative value character set combination. Match any character not included. For example,[^abc]"Can match"plain"In"p".
[A-Z] Character range. Matches any character in the specified range. For example,[a-z]"Can match"a"To"zAny lowercase letter in the range.
[^ A-Z] Negative character range. Matches any character that is not within the specified range. For example,[^a-z]"Can match anya"To"zAny character in the range.
\ B Match A Word boundary, that is, the position between a word and a space. For example,er\b"Can match"never"In"er", But cannot match"verb"In"er".
\ B Match non-word boundary. "er\B"Can match"verb"In"er", But cannot match"never"In"er".
\ CX Match the control characters specified by X. For example, \ cm matches a control-M or carriage return character. The value of X must be either a A-Z or a-Z. Otherwise, C is regarded as an original"c"Character.
\ D Match a numeric character. It is equivalent to [0-9].
\ D Match a non-numeric character. It is equivalent to [^ 0-9].
\ F Match a form feed. It is equivalent to \ x0c and \ Cl.
\ N Match A linefeed. It is equivalent to \ x0a and \ CJ.
\ R Match a carriage return. It is equivalent to \ x0d and \ cm.
\ S Matches any blank characters, including spaces, tabs, and page breaks. It is equivalent to [\ f \ n \ r \ t \ v].
\ S Match any non-blank characters. It is equivalent to [^ \ f \ n \ r \ t \ v].
\ T Match a tab. It is equivalent to \ x09 and \ CI.
\ V Match a vertical tab. It is equivalent to \ x0b and \ ck.
\ W Match any word characters that contain underscores. It is equivalent to[A-Za-z0-9_]".
\ W Match any non-word characters. It is equivalent to[^A-Za-z0-9_]".
\ XN Match n, where N is the hexadecimal escape value. The hexadecimal escape value must be determined by the length of two numbers. For example,\x41"Match"A". "\x041"Is equivalent to"\x04&1". The regular expression can use ASCII encoding ..
\ Num Matches num, where num is a positive integer. References to the obtained matching. For example,(.)\1"Matches two consecutive identical characters.
\ N Identifies an octal escape value or a backward reference. If at least N subexpressions are obtained before \ n, n is backward referenced. Otherwise, if n is an octal digit (0-7), n is an octal escape value.
\ Nm Identifies an octal escape value or a backward reference. If at least one child expression is obtained before \ nm, the NM is backward referenced. If at least N records are obtained before \ nm, n is a backward reference followed by text M. If none of the preceding conditions are met, if n and m are Octal numbers (0-7), \ nm matches the octal escape value nm.
\ NML If n is an octal number (0-3) and M and l are Octal numbers (0-7), the octal escape value NML is matched.
\ UN Match n, where n is a Unicode character represented by four hexadecimal numbers. For example, \ u00a9 matches the copyright symbol ().

 

Common Regular Expressions

 

User Name /^ [A-z0-9 _-] {} $/
Password /^ [A-z0-9 _-] {6, 18} $/
Hexadecimal value /^ #? ([A-f0-9] {6} | [a-f0-9] {3}) $/
Email /^ ([A-z0-9 _\. -] +) @ ([\ da-Z \. -] + )\. ([A-Z \.] {2, 6}) $/
/^ [A-Z \ D] + (\. [A-Z \ D] +) * @ ([\ da-Z] (-[\ da-Z])?) + (\. {1, 2} [A-Z] +) + $/
URL /^ (HTTPS? :\/\/)? ([\ Da-Z \. -] + )\. ([A-Z \.] {2, 6}) ([\/\ W \. -] *) * \/? $/
IP address /(2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) \.) {3} (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) /
/^ (? :(? : 25 [0-5] | 2 [0-4] [0-9] | [01]? [0-9] [0-9]?) \.) {3 }(? : 25 [0-5] | 2 [0-4] [0-9] | [01]? [0-9] [0-9]?) $/
HTML Tag /^ <([A-Z] +) ([^ <] + )*(? :> (. *) <\/\ 1> | \ s + \/>) $/
Delete Code \ comments (? <! HTTP: | \ s) //. * $
Range of Chinese Characters in Unicode encoding /^ [\ U2e80-\ u9fff] + $/

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.