I need to parse url in JavaScript.
Here is my code:
var myRe = /\?*([^=]*)=([^&]*)/;
var myArray = myRe.exec("?page=3&Name=Alex");
for(var i=1;i<myArray.length;i++)
{
alert(myArray[i]);
}
Unfortunately it only works for first name=value pair.
How I can correct my code?
execreturns a match, or null if no match found. So you need to keepexecing until it returns null.Also, you’re regex is wrong, it definately needs th
gswitch, but I got it working using this regex:See Live example: http://jsfiddle.net/GyXHA/