I am trying to find URL form a sting. I want to check if string contain any URL.
For that sake i wrote code :
function get_url_from_string(str) {
var searchText = str,
urls = searchText.match(/\b(http|https)?(:\/\/)?(\S*)\.(\w{2,4})\b/ig);
for (var i = 0, il = urls.length; i < il; i++) {
var ur=urls[i];
}
return ur;
}
But it returning only URL with out any parameter. For Example if i pass:
Hi Check This https://www.youtube.com/watch?v=eHOc-4D7MjY
It gives me https://www.youtube.com Only
I want to get full url. I have no idea of regular expression. Please help. Thanks
\b(?:https?)?(:\/\/)?\S*\.\w{2,4}[^\s]+\.(\w{2,4}says match a.then 2-4 characters of[a-zA-Z0-9_]. So your expression ends at the.com. Adding\S*after the\w{2,4}would allow it to continue until it hit a whitespace. regex101.com/r/rI1nN4/1\b(http|https)?(:\/\/)?(\S*)\.(\w{2,4})\b.(\S*):) Thanks For your help.(http|https)?into `(https?)?