Regex remove plus addressing + from email address

Viewed 496

I want to remove everything from the + up to the @, including the +, but not the @

The closest that I have been able to get is using this between regex.

>>> email = "garry+filter@gmail.com"
>>> re.sub(r'\+[^)]*\@', '', email)

garrygmail.com
1 Answers

Put @ in the replacement string, rather than an empty string.

re.sub(r'\+[^)]*@', '@', email)

BTW, there's no need to escape @.

Related