$re = '/^(?P<Username>[-\w\.]+)(?:\s+\W*at\W*\s+|\s*[^\@\s]*?@[^\@\s]*?\s*)(?P<Domain>([\w\-]+)(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))+?(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))??$)/m';
$str = 'Parse email, also distorted ones, and convert them back to the real ones.
Inspirated by dislick\'s work: https://regex101.com/r/wB7xJ7/1
frenci98@gmail.com
st11389@copernico.bo.it
gigilafontana .at. gmail [dot] com
d98.copernico@gmail.com
domenico-tosello at dotcom-sas dot com
my.e-M4il [at] w3-spAce.org
email@sub-sub.sub dot domain dot info
email@foo dot foo dot foo dot foo';
$subst = "\1@\3.\4";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php