I need to parse url in JavaScript.
Here is my code:
var myRe = /\\?*([^=]*)=([^&]*)/;
var myArray = myRe.exec(\"?page=3&Name=Alex\");
for(var i
exec
returns a match, or null if no match found. So you need to keep exec
ing until it returns null.
var myRe = /\?*([^=]*)=([^&]*)/;
var myArray;
while((myArray = myRe.exec("?page=3&Name=Alex")) !== null)
{
for(var i=1;i
Also, you're regex is wrong, it definately needs th g
switch, but I got it working using this regex:
var regex = /([^=&?]+)=([^&]+)/g;
See Live example: http://jsfiddle.net/GyXHA/