I want to extract the first valid URL in a string, which can be anywhere between characters and whitespace
I have tried with the following
...
urlReg
Live Demo with regex explanation on left side.
Regex explanation
var regex = /^(https?:\/\/[^/]+(\/[\w-]+)+)/;
var str = 'https://medium.com/aspen-ideas/there-s-no-blueprint-26f6a2fbb99c random stuff sd';
var url = str.match(regex)[0];
document.write(url);