preg: how to write a preg pattern to get domain name from an email?
You can replace everything up to and including the @
symbol to get the domain. In Javascript:
var email = '[email protected]';
var domain = email.replace(/.*@/, "");
alert(domain);
Why not just do this.
var email = "[email protected]", i = email.indexOf("@");
if (i != -1) {
email = email.substring(i);
}
Regex isn't really required, you could also go email = email.split("@")[1];