Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex remove plus addressing + from email address

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 = "[email protected]"
>>> re.sub(r'\+[^)]*\@', '', email)

garrygmail.com
like image 468
Kalanos Avatar asked Oct 26 '25 08:10

Kalanos


1 Answers

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

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

BTW, there's no need to escape @.

like image 121
Barmar Avatar answered Oct 28 '25 21:10

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!