+ 2

How to avoid consecutive occurrences of digit in regex??

10th Jan 2020, 4:39 PM
AARTI SHELAR
AARTI SHELAR - avatar
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 ;)
11th Jan 2020, 8:19 AM
Tibor Santa
Tibor Santa - avatar
+ 2
As in, you want digits which occur in singles and not in groups?
10th Jan 2020, 5:16 PM
👑 Prometheus 🇾🇬
👑 Prometheus 🇾🇬 - avatar
10th Jan 2020, 5:26 PM
AARTI SHELAR
AARTI SHELAR - avatar
0
🌟(Pro)metheus 🇾🇬 yes , I want to make aUID for company employees For that no digit will be consecutive occur 4 or more time
10th Jan 2020, 5:29 PM
AARTI SHELAR
AARTI SHELAR - avatar
0
Do you have to use a regex?
10th Jan 2020, 5:55 PM
rodwynnejones
rodwynnejones - avatar
10th Jan 2020, 6:14 PM
AARTI SHELAR
AARTI SHELAR - avatar
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
10th Jan 2020, 7:24 PM
Tibor Santa
Tibor Santa - avatar
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.
10th Jan 2020, 7:35 PM
rodwynnejones
rodwynnejones - avatar
0
Tibor Santa your program work but it gives error for input as " 5252248277877418"
11th Jan 2020, 7:04 AM
AARTI SHELAR
AARTI SHELAR - avatar
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. ;)
11th Jan 2020, 7:51 AM
Tibor Santa
Tibor Santa - avatar
0
77-77 is not valid and 77877 is valid
11th Jan 2020, 7:54 AM
AARTI SHELAR
AARTI SHELAR - avatar
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
11th Jan 2020, 9:31 AM
AARTI SHELAR
AARTI SHELAR - avatar