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?
如果您遇到自己的问题,该工具应该可以工作:
[(+\d]\d[-\d\s()]*\d
it's working if you replace one of the * to +
mobile = re.findall(r'+?(\\d+)\\s?(?(\\d*))?\\s?(\\d*)[\\s-]?(\\d*)\\s?(\\d*)\\s?(\\d*)\\s?', text)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.