regex - JavaScript to remove whatever is after the tld and before the whitespace -


i have bunch of functions filtering page down domains attached email addresses. it's working great except 1 small thing, of links coming out this:

example.com
example.org.
example.org>.
example.com"
example.com".
example.com).
example.com(comment)"
dept.example.com
example.org
example.com.

i want figure out 1 last filter (regex or not) remove after tld. of these items in array.

edit

the function i'm using:

function filterbydomain(array) {     var regex = new regexp("([^.\n]+\.[a-z]{2,6}\b)", 'gi');     return array.filter(function(text){         return regex.test(text);     }); } 

you can use regex match tld each case:

/^[^.\n]+\.[a-z]{2,63}$/gim 

regex demo

you validation function can be:

function filterbydomain(array) {     var regex = /^[^.\n]+\.[a-z]{2,63}$/gim;     return array.filter(function(text){         return regex.test(text);     }); } 

ps: read q & see 63 characters allowed in tld.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -