Hi there,

I'm trying out a regex to match urls, and my expression needs to contain parentheses. If I were using PHP's preg_match_all function it would return a multi-dimensional array of matches, and then each match in parenthesis.

As far as i can make out from my research online, javascript's match function with the /g modifier will behave in a simliar way, returning an array of matches. All good in da hood, except when parentheses appear in the regex.

Here's my regex:
/(https?:\/\/)?www\.[-a-zA-Z0-9_]+\.[a-z\.]{3,5}(\/[-a-zA-Z0-9\?\=]+)?/gi
Now, on a string like this:
I get this array:

matches[0]: www.youtube.com/watch?=aBgFFdqn
matches[1]: undefined
matches[2]: /watch?=aBgFFdpn

Is there anyway to get an array of just the full matches, or even a multi-dimensional array of full matches and parenthesis matches, or is there a better way of approaching this?

Many thanks,
Mike