问题
How do i write a regex to handle all instances where a the substring is 6 or more consecutive numbers such as this?
000000
111111
222222
333333
444444
555555
I tried [0-9]{6,}.
I plan to negative this afterwards so I can nullify strings with these cases.
Thanks in advance!
回答1:
To match strings only consisting of 6 or more identical digits, you may use
^([0-9])\1{5,}$
The pattern matches:
^- start of string([0-9])- Capturing group 1 matching a digit\1{5,}- 5 or more occurrences (due to the limiting quantifier{5,}) of the value captured into Group 1 (where\1is a backreference to Group 1 value)$- end of string.
来源:https://stackoverflow.com/questions/42001668/regular-expression-for-same-consecutive-numbers