Regular Expressions and Regular Expressions

Source: Internet
Author: User

Regular Expressions and Regular Expressions
1. ^ \ D + $ // Note: match a non-negative integer (positive integer + 0)
2. ^ [0-9] * [1-9] [0-9] * $ // Note: match a positive integer
3. ^ (-\ D +) | (0 +) $ // Note: match a non-positive integer (negative integer + 0)
4. ^-[0-9] * [1-9] [0-9] * $ // Note: match a negative integer
5. ^ -? \ D + $ // annotation: matches an integer positive integer and pays an integer and 0
6. ^ \ D + (\. \ d + )? $ // Annotation: Match non-negative floating point number (Positive floating point number + 0)
7. ^ ([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // Note: match the Positive floating point number
8. ^ (-\ D + (\. \ d + )?) | (0 + (\. 0 + )?)) $ // Annotation: match a non-Positive floating point number (negative floating point number + 0)
9. ^ (-([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // annotation: matches a negative floating point number.
10. ^ (-? \ D +) (\. \ d + )? $ // Annotation: Match floating point number
11. ^ [A-Za-z] + $ // Note: match A string consisting of 26 English letters
12. ^ [A-Z] + $ // Note: match a string consisting of 26 uppercase letters
13. ^ [A-z] + $ // Note: match a string consisting of 26 lower-case letters
14. ^ [A-Za-z0-9] + $ // Note: match a string consisting of digits and 26 letters
15. ^ \ W + $ // Note: match a string consisting of digits, 26 English letters, or underscores
16. ^ [\ W-] + (\. [\ w-] +) * @ [\ w-] + (\. [\ w-] +) + $ // Note: matching email address
17. ^ [A-zA-z] +: // Note: match (\ w + (-\ w + )*)(\. (\ w + (-\ w + )*))*(\? \ S *)? $ // Annotation: matching url
18. Note: Regular Expression matching Chinese characters: [\ u4e00-\ u9fa5]
19. Note: Match double-byte characters (including Chinese characters): [^ \ x00-\ xff]
20. Application: Calculate the length of a string (two-byte length Meter 2, ASCII character meter 1)
String. prototype. len = function () {return this. replace ([^ \ x00-\ xff]/g, "aa"). length ;}
21. Note: Regular Expression matching empty rows: \ n [\ s |] * \ r
22. Note: Regular Expressions matching HTML tags:/<(. *)>. * <\/\ 1> | <(. *) \/>/
23. Note: Regular Expressions matching spaces at the beginning and end are as follows: (^ \ s *) | (\ s * $)


* Use Cases of Regular Expressions
* 1, ^ \ S + [a-z A-Z] $ cannot be blank cannot have spaces can only be English letters
* 2. \ S {6,} cannot be empty for more than six characters
* 3. ^ \ d + $ cannot contain spaces or non-numbers.
* 4. (. *) (\. jpg | \. bmp) $ can only be in jpg and bmp formats.
* 5. ^ \ d {4} \-\ d {} $ can only be in the format of 2004-10-22
* 6. select at least one item for ^ 0 $.
* 7. ^ 0 {2,} $ select at least two items.
* 8. ^ [\ s | \ S] {20,} $ cannot be empty for more than 20 words
* 9. ^ \ +? [A-z0-9] ([-+.] | [_] + )? [A-z0-9] +) * @ ([a-z0-9] + (\. | \-) + [a-z] {2, 6} $ email
* 10. \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w +) * ([,;] \ s * \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w +) * enter multiple addresses separated by commas (,) or spaces.
* 11, ^ (\ ([0-9] + \))? [0-9] {87341628} $ a telephone number with a 7-or 8-digit phone number or a District Code such as (022)
* 12, ^ [a-z A-Z 0-9 _] + @ [a-z A-Z 0-9 _] + (\. [a-z A-Z 0-9 _] +) + (\, [a-z A-Z 0-9 _] + @ [a-z A-Z 0-9 _] + (\. [a-z A-Z 0-9 _] +) * $
* Only letters, numbers, and underscores are allowed. @ and. must be in the same format as a standard email.
* 13 ^ \ w + @ \ w + (\. \ w +) + (\, \ w + @ \ w + (\. \ w +) * $ the above expression can also be written in this way, which is more refined.
14 ^ \ w + (-\ w +) | (\. \ w +) * \ @ \ w + ((\. |-) \ w + )*\. \ w + $ [/size]

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.