I am trying to match repeating 3 digit groups that appear in a uk phone number. I already can get the match when the 3 digits are identical in the groups with this pattern r'(\d)\1{2}'
Eg when input is "07119777777" I get two matches:
<re.Match object; span=(5, 8), match='777'>
<re.Match object; span=(8, 11), match='777'>
However when input is something like "07123123123" I get no matches as the digits inside the 3 digit group are different. Is there a regex pattern to identify these as matches?
Would you please try the following:
str = "07590759759"
m = re.search(r'(\d{3}).*?(\1).*?(\1)', str)
print(m.groups())
Output:
('759', '759', '759')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.