Trying to help grab unique emails for a contest and have a few people using the gmail + symbol trick to get around it. I'm trying to get a clean way to filter the email so it removes everything in between the + and @ symbol so that:
tester+dn2934u2@gmail.com
becomes:
tester@gmail.com
So far I have:
\+(.*?)\@
which removes the + and @ symbols. Is there a way (and I'm sure there is) to tell regex to keep the @ character so I don't need to re-add it, replace it, or some other trick?
You can use this:
\+[^@]+(?=@)
(?=@)
is a lookahead assertion (its only a check) and means followed by @
Put it within your selector?
eg \+(.*?\@)
Just include the @ into the capture group:
\+(.*?@)
You can use this to match everything but the @ symbol:
\+[^@]+
Full php code:
$mail = preg_replace('%\+[^@]+%', '', $mail);
$email_stripped = preg_replace("/^(.+?)(\+.+)?(@.+)$/", "$1$3", $email);