Skip to content

Instantly share code, notes, and snippets.

@Avidid
Created July 30, 2013 16:48
Show Gist options
  • Save Avidid/6114724 to your computer and use it in GitHub Desktop.
Save Avidid/6114724 to your computer and use it in GitHub Desktop.
Extract domain from email address using regex
<?php
$regex = '/@((([^.]+)\.)+)([a-zA-Z]{3,}|[a-zA-Z.]{5,})/';
preg_match($regex, '[email protected]', $matches);
print_r($matches);
preg_match($regex, '[email protected]', $matches);
print_r($matches);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment