This should be very simple (when you know the answer). From this question
I want to give the posted solution a try. My question is:
How to get the parameter value of a given URL using JavaScript regular expressions?
I have:
http://www.youtube.com/watch?v=Ahg6qcgoay4
I need:
Ahg6qcgoay4
I tried:
http://www.youtube.com/watch\\?v=(w{11})
But: I suck...
v is a query parameter, technically you need to consider cases ala: http://www.youtube.com/watch?p=DB852818BF378DAC&v=1q-k-uN73Gk
In .NET I would recommend to use
System.Web.HttpUtility.ParseQueryString
And you don't even need to check the key, as it will return null if the key is not in the collection.
You almost had it, just need to escape special regex chars:
Edit: Fix for regex by soupagain.
I know the question is Old and already answered but this can also be a solution
and I checked these two URLs
DEMO
I use seperate custom functions which gets all URL Parameters and URL parts . For URL parameters, (which is the final part of an URI String, http://domain.tld/urlpart/?x=a&y=b
The above function will return an array consisting of url variables.
For URL Parts or functions, (which is http://domain.tld/urlpart/?x=a&y=b I use a simple uri split,
You can even combine them both to be able to use with a single call in a page or in javascript.
Why dont you take the string and split it
Example on the url
you can do a split as
You will get array of strings with params as name value pairs with "=" as the delimiter.
Not tested but this should work: