Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preg: how to write a preg pattern to get domain name from an email?

Tags:

From an email address like [email protected] I want to fetch domain name gmail.com. i want to use that pattern on textbox value in Javascript.

Pease suggest me an optimized and faster preg pattern for above requirement...

like image 456
Vinay Jeurkar Avatar asked Mar 03 '11 14:03

Vinay Jeurkar


1 Answers

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); 
like image 165
Andy Avatar answered Oct 25 '22 21:10

Andy