Here's a straightforward question for you. Regex can sometimes get tricky, so thank goodness for simplifying things...
In the URL, there's a query parameter labeled ?id=0061ecp6cf0q
.
I want to match it and only retrieve the part after the equals sign.
This is the regex I've come up with:
(?:\?id=){1}([a-z0-9])+
Now, when I use this regex in JavaScript on a string containing the query parameter, the .match() function returns an array with one entry: "?id=0061ecp6cf0q".
But, if I use .exec() on the same regex with the query string as input, I receive an array with two items:
array[0] = "?id=0061ecp6cf0q"
array[1] = "q"
I'm left scratching my head at two things: 1) Why is my supposed non-capturing group capturing? 2) And why does it grab "q" out of all possibilities?