List all the matched regex in a string
## Suppose we have a text with many email addresses
str = 'My official email id is debojyotib@nrifintech.com and my personal email id is debjyoti.mail@gmail.com '
import re
## Here re.findall() returns a list of all the found email strings
emails = re.findall(r'[\w\.-]+@[\w\.-]+', str) ## ['alice@google.com', 'bob@abc.com']
print '\nThe String is : ', str, '\n'
print 'The number of emails in the string : ', len(emails), '\n'
for email in emails:
print email, '\n'
Output:
The String is : My official email id is debojyotib@nrifintech.com and my personal email id is debjyoti.mail@gmail.com
The number of emails in the string : 2
debojyotib@nrifintech.com
debjyoti.mail@gmail.com