How to remove . (dot) from email before @ using regex?

by elisha_langworth , in category: Third Party Scripts , 21 days ago

How to remove . (dot) from email before @ using regex?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 21 days ago

@elisha_langworth 

You can use the following regex pattern to remove a dot before the @ symbol in an email address:

1
.(?=[^@]*@)


Here is how you can do this in Python:

1
2
3
4
5
6
import re

email = "[email protected]"
cleaned_email = re.sub(r'.(?=[^@]*@)', '', email)

print(cleaned_email)


This code snippet will remove any occurrence of a dot before the @ symbol in the email address "[email protected]" and print the cleaned email address without the dot.