Regular Expression to determine the number nickname type

Source: Internet
Author: User

Nickname Detection: It can mainly detect Connection Numbers (12345, 65432), AABB, mobile phone number, date number (birthday number, year number), abbcabb number, and replay numbers with more than three digits.

More types of number detection can be modified according to the following expression.

1. Match 6 bits (? : 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {5} \ D

2. Match 6-digit downgrading (? : 9 (? = 8) | 8 (? = 7) | 7 (? = 6) | 6 (? = 5) | 5 (? = 4) | 4 (? = 3) | 3 (? = 2) | 2 (? = 1) | 1 (? = 0) {5} \ D

3. Match the 6-digit ascending or descending order (? :(? : 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {5} | (? : 9 (? = 8) | 8 (? = 7) | 7 (? = 6) | 6 (? = 5) | 5 (? = 4) | 4 (? = 3) | 3 (? = 2) | 2 (? = 1) | 1 (? = 0) {5}) \ D

4. Match 4-9 consecutive digits (? :(? : 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {3,} | (? : 9 (? = 8) | 8 (? = 7) | 7 (? = 6) | 6 (? = 5) | 5 (? = 4) | 4 (? = 3) | 3 (? = 2) | 2 (? = 1) | 1 (? = 0) {3,}) \ D

5. Match repeated numbers with more than three digits ([\ D]) \ 1 {2 ,}

6. match the number of the date type (19 | 20) [\ D] {2} (1 [0-2] | 0? [1-9]) (31 | 2 [0-9] | 1 [0-9] | 0? [0-9])

7. Mobile phone number (13 [0-9] | 15 [0-9] | 18 [0-9]) ([\ D] {2, 4}) {2}

8. Match the 33111 type ([\ D]) \ 1 {1,} ([\ D]) \ 2 {2 ,}

9. Match ([\ D]) {1,} ([\ D]) {1,}) \ 1 {1,} of the 5331533 type ,}

10, matching 22334,123355 ([\ D]) \ 1 {1,} ([\ D]) \ 2 {1 ,}

11. Last Match $

// AABB, allows AAAA
(\ D) \ 1 (\ D) \ 2 $
// Abab, AAAA allowed
(\ D) \ 1 \ 2 $
// Aaab, allows AAAA
(\ D) \ 1 \ 1 \ D $
// Allow both
(? :( \ D) \ 1 (\ D) \ 2 | (\ D) \ 3 \ 4 | (\ D) \ 5 \ 5 \ D) $
// If AAAA is not allowed, change the second (\ D) ((?! \ 1) \ D)


// Such as AABB, AAAA is not allowed
(\ D) \ 1 ((?! \ 1) \ D) \ 2 $

VaR Reg = new Regexp ("(?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {5} \ D "," G "); If (phone. Match (REG )! = NULL) {code + = ', abcdef';} var Reg = new Regexp ("(?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D "," G "); If (phone. Match (REG )! = NULL) {code + = ', abc';} var Reg = new Regexp ("^ (?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D [\ D] [\ D] (?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (0, 3) = result. substring (5, 8) {code + = ', ABC ** abc';} var Reg = new Regexp ("[\ D] (?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D [\ D] (?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D $ "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (1, 4) = result. substring (5, 8) {code + = ', * ABC * abc';} var Reg = new Regexp ("(\ D )((?! \ 1) \ D) \ 2 [\ D] "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (0, 1) = result. substring (3, 4) {code + = ', abba';} var Reg = new Regexp ("(?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D {4} "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (0, 3) = result. substring (3, 6) {code + = ', abcabc';} var Reg = new Regexp ("^ (?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D {4} "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (0, 3) = result. substring (3, 6) {code + = ', abcabc *';} var Reg = new Regexp ("(?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ D {3} "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (0, 2) = result. substring (3, 5) {code + = ', abcab';} var Reg = new Regexp ("(?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {3} \ D "," G "); If (phone. Match (REG )! = NULL) {code + = ', abcd';} var Reg = new Regexp ("(?: 0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {3} \ D {5} "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (0, 4) = result. substring (4, 8) {code + = ', abcdabcd';} var Reg = new Regexp ("(\ D )((?! \ 1) \ D) \ 1 \ 2 \ 1 \ 2 "," G "); If (phone. Match (REG )! = NULL) {code + = ', ababab';} var Reg = new Regexp ("^ (\ D )((?! \ 1) \ D) \ 1 \ 2 \ 1 \ 2 "," G "); If (phone. Match (REG )! = NULL) {code + = ', ababab *';} var Reg = new Regexp ("(\ D )((?! \ 1) \ D) \ 1 \ 2 "," G "); If (phone. Match (REG )! = NULL) {code + = ', abab';} var Reg = new Regexp ("^ (\ D )((?! \ 1) \ D) [\ D] [\ D] (\ D )((?! \ 1) \ D) [\ D] [\ D] "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (0, 2) = result. substring (4, 6) {code + = ', AB **';}} vaR Reg = new Regexp ("[\ D] [\ D] (\ D )((?! \ 1) \ D) [\ D] [\ D] (\ D )((?! \ 1) \ D) $ "," G "); If (phone. Match (REG )! = NULL) {var result = phone. match (REG ). tostring (); If (result. substring (2, 4) = result. substring (6, 8) {code + = ', ** AB ** AB';} var Reg = new Regexp ('([\ D]) \ 1 {4,} ', "G"); If (phone. match (REG )! = NULL) {code + = ', aaaaa';} var Reg = new Regexp ('(.) \ 1 {3} ', "G"); If (phone. match (REG )! = NULL) {code + = ', AAAA';} var Reg = new Regexp ('(\ D) \ 1 \ 1 ((?! \ 1) \ D) ', "G"); If (phone. Match (REG )! = NULL) {code + = ', aaab';} var Reg = new Regexp ('(.) \ 1 {2} ', "G"); If (phone. match (REG )! = NULL) {code + = ', aaa';} var Reg = new Regexp ('(.) \ 1 {1} ', "G"); If (phone. match (REG )! = NULL) {code + = ', AA';} // aabbb var Reg = new Regexp ("(\ D) \ 1 ((?! \ 1) \ D) \ 2 \ 2 "," G "); If (phone. Match (REG )! = NULL) {code + = ', aabbb';} // AABB var Reg = new Regexp ("(\ D) \ 1 ((?! \ 1) \ D) \ 2 "," G "); If (phone. Match (REG )! = NULL) {code + = ', AABB';} // aabcc var Reg = new Regexp ("(\ D) \ 1 ((?! \ 1) \ D )((?! \ 1) \ D) \ 3 "," G "); If (phone. Match (REG )! = NULL) {var result = phone. Match (REG). tostring (); If (result. substring (2, 3 )! = Result. substring (0, 1) & result. substring (2, 3 )! = Result. substring (3, 4) {code + = ', aabcc';} var Reg = new Regexp ("(\ D) \ 1 ((?! \ 1) \ D) \ 2 ((?! \ 1) \ D) \ 3 "," G "); If (phone. Match (REG )! = NULL) {var result = phone. Match (REG). tostring (); If (result. substring (2, 4 )! = Result. substring (0, 2) & result. substring (2, 4 )! = Result. substring (4, 6) {code + = ', aabbcc';} var Reg = new Regexp ("^ (\ D) \ 1 ((?! \ 1) \ D) \ 2 ((?! \ 1) \ D) \ 3 "," G "); If (phone. Match (REG )! = NULL) {var result = phone. Match (REG). tostring (); If (result. substring (2, 4 )! = Result. substring (0, 2) & result. substring (2, 4 )! = Result. substring (4, 6) {code + = ', aabbcc *';}}

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.