I am outputting log messages and need to obscure the email addresses in them.
A log message might look like this:
A lead was saved for sharon.davis@example.com, Date: 11th December 2019, Service: Car Hire ( Premium ), Extras: NA, Price: £300
I am using:
preg_replace('/(?<=.).(?=.*?@)|(?<=@.).*(?=\.com)/u', '*', $email);
I am using this regex to obscure emails, which works great when it's just an email, but in a sentence, it does this....
A********************************@example.com, Date: 11th December 2019, Service: Car Hire ( Premium ), Extras: NA, Price: £300
Is there a way to only make it go back as far as the space?
So the required result would be:
A lead was saved for ************@example.com, Date: 11th December 2019, Service: Car Hire ( Premium ), Extras: NA, Price: £300",