+ 2
How to avoid consecutive occurrences of digit in regex??
12 Respostas
+ 1
It's really easy to adjust to only look for consecutive repetitions, not overall anywhere in the string.
.* means any character (between the same checked digits
replace with -? That means an optional dash or nothing.
rep4 = compile(r'.*(\d)-?\1-?\1-?\1')
You get help more easily if you can accurately specify your problem and people don't need to do much guesswork ;)
+ 2
As in, you want digits which occur in singles and not in groups?
0
đ(Pro)metheus đžđŹ yes , I want to make aUID for company employees
For that no digit will be consecutive occur 4 or more time
0
Do you have to use a regex?
0
rodwynnejones yes
0
rep4 = compile(r'.*(\d).*\1.*\1.*\1')
This matches any digit that is repeated at least 4 times. If there is no match then your input is valid. You can combine it with the other criterion (of format) as 2 separate regexp.
https://code.sololearn.com/cW16Sb5MW1D4/?ref=app
0
Give a few more examples of valid and in-valid inputs and explain why.
I don't think it can be done in the actual repression.. but you can carry out tests on what's returned if you group them.
0
Tibor Santa your program work but it gives error for input as " 5252248277877418"
0
I don't see any errors, it returns Invalid.
Anyway, feel free to adjust the code according to your needs, I've only highlighted a possible solution. ;)
0
77-77 is not valid and 77877 is valid
0
https://code.sololearn.com/c5zxiBUHM3Kv/?ref=app
Tibor Santa your expression is really best thanks I post the code for other which don't know how avoid repetition