I am using regex to classify special numbers.
The pattern I wish to match looks like this : 5ABCDXXYY
.
Its a number that:
- starts with "5"
- followed by 4 different digits (
ABCD
) - then 2 matching digits (
XX
) - and again 2 matching digits (
YY
)
examples the regex should match:
590631122
, 510367722
examples the regex shouldn't match:
566781100
, 519283412
I have tried the below
S_E_4_A = 590631122
S_E_4_A_pattern = re.sub(r'.{4}\d(\d)\1(\d)\2', "Special-Private", str(S_E_4_A))
print(S_E_4_A_pattern)
The problem with my regex is that it also match other patterns such as 5ABXXYYZZ
.
I want to change my regex to match only two sets of repeating numbers and not more.
Thank you