Skip to content

Instantly share code, notes, and snippets.

@Avidid
Created July 30, 2013 16:48
Show Gist options
  • Select an option

  • Save Avidid/6114724 to your computer and use it in GitHub Desktop.

Select an option

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, 'test@gmail.com', $matches);
print_r($matches);
preg_match($regex, 'test@google.co.uk', $matches);
print_r($matches);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment