javascript - Best regular expression for matching the domain part of emails -


i trying make regex can match domain portion of email address. right have use 2 of them, 1 gets email addresses , matches domain, i'm still having issues.

right code have this:

var email_ex = /[a-za-z0-9]+(?:(\.|_)[a-za-z0-9!#$%&'*+/=?^`{|}~-]+)*@(?!([a-za-z0-9]*\.[a-za-z0-9]*\.[a-za-z0-9]*\.))(?:[a-za-z0-9](?:[a-za-z0-9-]*[a-za-z0-9])?\.)+[a-za-z0-9](?:[a-za-z0-9-]*[a-za-z0-9])?/ig; // match email addresses on page     email_ex = new regexp(email_ex);      var domain_ex = /[a-za-z0-9\-\.]+\.(com|org|net|mil|edu|com|org|net|mil|edu|co\.uk|au|li|ly|it|io)/ig // match domains     domain_ex = new regexp(domain_ex);      var match = document.body.innertext; // location pull our text from. in case it's whole body     match = match.match(email_ex); // run regexp on body's textcontent 

i'd rather not have have list of tld's, haven't been able find expression enough

the simplest regexp: /@([^\s]*)/

var email = "test@example.domain"; var domain = email.match(/@([^\s]*)/)[1]; 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -