I am new to regex expressions in python and trying to find all occurrences of phone nos in a string wherein the country code with a + is not mandatory
import re
st="it contains std code +91-888-888-9999 and 777-897-4565"
pattern=r"(\+?\d{2}\-)?\d{3}-\d{3}-\d{4}"
c=re.findall(pattern,st)
if c is not None:
print(c)
else:
print("it is none")
If i use search it returns only the first match. Using findall it returns a list with the pattern in the bracket matched as the first value and empty as next
['+91-','']
If a change the pattern to
pattern=r"(\+?\d{2}\-)?(\d{3}-\d{3}-\d{4})"
i get list of tuples with country code as the first value and phone no as the second value. Can i get the entire value e.g +91-888-888-9999 as a single unit using search() and findall(). kindly update