I am trying to match all phone numbers from text.
This regex works well for me. When I check on regex match website. But when I use in actual code, it gives me wrong result
>>> text = 'my phone is +31 478-511014 and +91 900 133 5555'
>>> mobile = re.findall(r'\+?(\d*)\s?\(?(\d*)\)?\s?(\d*)[\s-]?(\d*)\s?(\d*)\s?(\d*)\s?', text)
>>> mobile
[('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('31', '478', '', '511014', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('', '', '', '', '', ''), ('91', '900', '133', '5555', '', ''), ('', '', '', '', '', '')]
Am I doing something wrong?
'my phone is +31 478-511014 and +91 900 133 5555') on the website it gives me pretty much the same result.\d*to\d+(...)create items in the resulting list of tuples, you need to either remove the unnecessary groups or turn those necessary ones into non-capturing. Or usere.finditeras in my demo. Although I have not considered+and-, so it is not a final answer.[('31', '478', '', '511014', '', ''), ('91', '900', '133', '5555', '', '')]How can I get exact phone number as result