I need a regex to match a string that:
- has only digits
0-9and spaces - all digits must be same
- should have at-least 2 digits
- should start and end with digits
Matches:
11 11111 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1
No matches:
1 has only one digit 11111 has space at the end 11111 has space at beginning 12 digits are different 11: has other character
I know regex for each of my requirement. That way I’ll use 4 regex
tests. Can we do it in one regex?
Yes it can be done in one regex:
Rubular link
Explanation: