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

by elisha_langworth , in category: Third Party Scripts , 5 months ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 5 months 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 = "john.doe@example.com"
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 "john.doe@example.com" and print the cleaned email address without the dot.

Related Threads:

How to remove end of substring using regex?
How to remove part of file name using a regex expression?
How to remove duplicate arithmetic operators using regex?
How to remove html tags from an html string using regex?
How to backreference group when using or in regex?
How to remove .git directory while using git clone?