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