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
That's because the match result holds the whole string first that matches, then the groups. I guess you want the group, so you can do this:
url[1]
Here's a fiddle: http://jsfiddle.net/jgt8u6pc/1/