Regular expressions are used to match consecutive numbers. Regular expressions are used to match consecutive numbers.

Source: Internet
Author: User

Regular expressions are used to match consecutive numbers. Regular expressions are used to match consecutive numbers.

The implementation requirements are as follows:

  • Pure number
  • Between 5-7 digits
  • The first three are the same
  • Starting from the fourth digit

Example:

11123 # correct 22234 # correct 33345 # correct 333456 # correct 2223456 # correct 0001234 # correct 00012345 # error: the length of the row exceeds 000234 # error: 3rd bits and 4th bits are not consecutive 111235 # error: 5th-bit and 6th-bit discontinuous

1. match three identical numbers

(\ D) \ 1 {2}

2. Matching continuous numbers

You can use the assertion of Zero Width to match continuous numbers. Of course, there is no good way to match them. You can only list them. The following two rows can match three consecutive numbers.

(0 (? = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (? = 9) {2} \ d ((? <= 0) 1 | (? <= 1) 2 | (? <= 2) 3 | (? <= 3) 4 | (? <= 4) 5 | (? <= 5) 6 | (? <= 6) 7 | (? <= 7) 8 | (? <= 8) 9) {2}

Note:The first line adopts the positive zero-width assertion, and the second line adopts the reverse zero-width assertion.

Want to know

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.