Friday 25 August 2017

Fetch Full Url from String by Javascript

 
//Remove Html code from string 
var textString = code.replace(/<\/?[^>]+(>|$)/g, " ").replace(/^(&nbsp;|nbsp;)+/g, '').trim(); //Match full url and generate a array
var urls = textString.match(/\b(http(s)?(:\/\/))?(www.)?[a-zA-Z0-9-_.]+(.[a-zA-Z0-9]{2,}).*?(\.\w+)([-a-zA-Z0-9:%_+.~#?&\/\/=]*)/ig);

//Remove content before http
var url =  /http(.+)/.exec(urls[0])[0];

No comments:

Post a Comment