Write a python function to find all email-id patterns in a given string and write to a user input file


Topic: Write a python function to find all email-id patterns in a given string and write to a user input file

Solution

import re
def extract_mailid(my_string, outfile):
    regex = re.compile(r'[\w]+@[\w]+\.[\w]+', re.UNICODE)    
    mailids = regex.findall(my_string)
    if(len(mailids) > 0):
        with open(outfile, 'w') as mailfile:
            for mailid in mailids:
                mailfile.write(mailid+"\n")
        mailfile.close()



List all Python Programs