I’m using this simple code:
$raw = 'text hi@li.com text';
$raw = preg_replace('<[\w.]+@[\w.]+>', '***@$2', $raw);
And i should get as output, something like ***@li.com; while i get ***@
I can’t debug it, i don’t know how what’s wrong.
So the solution is
preg_replace('<([\w.]+)@([\w.]+)>', '***@$2', $raw);
I had to add () to make a group.
you need to create a group by adding (), and BTW it’s gonna be $1:
also modified .+ tp [^\s]+ so it “eats” only the email and not the text after it