Now in the text we will search for the telephone number of Ukraine in the international format, the template of which is as follows: +380(67)777-7-777 or +380(67)777-77-77
Write a regular expression for the find_all_phones function, which will find all phone numbers according to the specified pattern in the text (parameter text) and return a list of matches obtained from the text.
For the sake of simplification, let's assume that:
we use only numbers and symbols +, (, ) and - the phone number starts with the + symbol phone pattern symbol + then three digits 380, symbol (, two digits, symbol ), three digits, symbol -, one or two digits, symbol -, two or three digits The length of the phone number template is always 17 characters This regular expression by no means claims to cover all possible variants of phone numbers.
import re
def find_all_phones(text):
result = re.findall(r"(\+380\(\d{2}\)\d{3}-\d{1,2})", text)
return result
The find_all_phones function returns an incorrect result: ['+380(67)777-7-77', '+380(67)777-77-77', '+380(67)777-77-78']. It was expected that the find_all_phones function when receiving the parameter 'Irma +380(67)777-7-771 second +380(67)777-77-77 aloha a@test.com abc111@test.com.net +380(67)111 -777-777+380(67)777-77-787' will return the following list ['+380(67)777-7-771', '+380(67)777-77-77', '+380(67 )777-77-78']