Replace email id by HTML Tag to make a hyperlink inside the text

I have a text as follows

For further details, please contact abc.helpdesk@xyz.com

I want to replace the email ID mentioned in the above text by <a href "abc.helpdesk@xyz.com">abc.helpdesk@xyz.com</a> So that the email ID would become a clickable object when the above text would be presented on web page

So far I have tried out following

text = 'For further details, please contact abc.helpdesk@xyz.com'
email_pat = re.findall(r'[\w\.-]+@[\w\.-]+\.\w+',text)
email_str = ' '.join(email_pat) #converts the list to string
text_rep = ext.replace(email_str,'<a href "email_str">email_str</a>')

The above code replace the email string but instead of creating hyperlink it actually does the following

For further details, please contact <a href "email_str">email_str</a>

Is there any way to tackle this?

#python #html #regex

3 Likes2.00 GEEK