Partially hides email address with PHP regex
I found two threads that at first seem to answer my query, but they only seem to be part of the solution to me. Using them, I got to where I am. So this is not a duplicate!
I want to replace everything except the first character in the name and domain part of an email address with an asterisk:
eg
g ****** @g ****. com or g ****** @g ****. co.uk
code:
$email2 = preg_replace('/(?<=.).(?=.*@)/', '*', $email);
$email3 = preg_replace('/(?<=@.)[a-zA-Z0-9-]*(?=(?:[.]|$))/', '*', $email2);
which almost exists, but gives me g ****** @g * .com , not g ****** @g *****. com
Can anyone help me with regex?
+3
source to share
2 answers