import re
a = "Office: (000) 987-9728, Mobile: (000) 312-9725"
b = "Mobile: (000) 312-8750, Office: (000) 987-9728"
c = "Mobile: (000) 312-8750"
d = "Office: (000) 987-9728"
search_office_phone = re.search("Office:\s?(.*),|Office:\s?(.*)",a)
if search_office_phone:
office_number = search_office_phone.group(1)
print(office_number)
Required solution: (000) 987-9728, (000) 312-9725
This are the various text that can be formed, but using regex I need to got the solution above.
>Solution :
[re.sub(r"Office: |Mobile: ", "", s) for s in [a, b, c, d]]