I'm trying to extract phone numbers from some text
the problem is im getting 4 different matches, where I only want the full match of this particular expression. for example, I get:
Match 1
1. 054-434-4321
2. 054
3. -
4. -
Match 2
1. (03) 502 9571
2. (03)
3.
4.
as you can see, I only need the first match out of this list.
here is my code :
text = "You can reach me at 054-434-4321, or my office at (03) 502 9571 or (050) 223 957.\
Send me a fax at 03 502 7422. We finally made the sale for all 977 giraffes.\
They wanted 225 957 dollars for it"
phone_pattern = re.compile(r'(\d{2,3}|\(\d{2,3}\))(-| )\d{3}(-| )\d{3,4})')
phone_results = phone_pattern.findall(text)
print(f'extracted {len(phone_results)} results : {phone_results}')
This is the regex :
(\d{2,3}|\(\d{2,3}\))(-| )\d{3}(-| )\d{3,4})
I've tried to place the parentheses at the end of the expression, in order to group results, with no aid.