import re
s = ' 1.210.223.1112 (113)-945-6373; 222.212.2333 (111)123-4567 (111)1234567 (111 )123-4567 \n(1-100-533-1710)the ( 111)123-4567 Z1902022 (111)123-4567 N18-2181 Z1234567 1-22-2001 (100) 115-5198 f: (110)-111-1111 112.222.1112 (222)-222-3337 (120) 305-1314'
I have a list of phone numbers and I would like to get all variations present in the string s
. From modification of selecting variations of phone numbers using regex I have tried the following
reg = r'\(?\s*\d?\s*-?\d{3}\s*[)-]?-?\s*\d{3}\s*-?\s*\d{4}\)?'
r1 = re.findall(reg,s)
r1
Which gives me close to what I want
['(113)-945-6373',
'(111)123-4567',
'(111)1234567',
'(111 )123-4567',
'(1-100-533-1710)',
'( 111)123-4567',
'(111)123-4567',
'(100) 115-5198',
'(110)-111-1111',
'(222)-222-3337',
'(120) 305-1314']
However, it is missing 1.210.223.1112
and 222.212.2333
.
I have tried modifying reg
by adding a .
but this doesn't give me what I am looking for
reg = r'\(?\s.*\d?\s*-?\d{3}\s*[)-]?-?\s*\d{3}\s*-?\s*\d{4}\)?'
My desired output is as follow which includes 1.210.223.1112
and 222.212.2333
['1.210.223.1112',
'(113)-945-6373',
'222.212.2333',
'(111)123-4567',
'(111)1234567',
'(111 )123-4567',
'(1-100-533-1710)',
'( 111)123-4567',
'(111)123-4567',
'(100) 115-5198',
'(110)-111-1111',
'(222)-222-3337',
'(120) 305-1314']
How do I alter reg
to get my desired output?