-1

Possible Duplicate:
Regex, get string value between two characters

myemail@gmail.com

What is the pattern to get what's between '@' and '.' in this string? In this case it would get 'gmail'.

Community
  • 1
  • 1
user1091856
  • 3,032
  • 6
  • 31
  • 42
  • 1
    Regex can't reliably parse an email. What if you had the email `abc@subdomain.host.com`. The regex you request would only match subdomain when you would likely be looking for the host only (or the host and subdomain). – Bailey Parker Jul 29 '12 at 05:32

2 Answers2

3

I believe it is ...

preg_match("'@(.*?)\.'si", $source, $match);
nullpotent
  • 9,162
  • 1
  • 31
  • 42
2
$email = 'myemail@gmail.com';
$gmail = preg_match('/@([^\.]*)\./', $email, $m) ? $m[1] : false;
Ross Smith II
  • 11,799
  • 1
  • 38
  • 43