regex - Parsing an URL in JavaScript -


I need to parse the URL in javascript.

Here's my code:

  var myRe = / \? * ([^ =] *) = ([^ & Amp; Amp;] *) /; Var myArray = myRe.exec ("? Page = 3 & name = Alex"); (Var i = 1; i & lt; myArray.length; i ++) {Warning (myArray [i]); }   

Unfortunately this only works for the first name = value pair.

How can I fix my code?

exec does not match, or if no match is found. So you need to keep exec ing till it is not empty.

  var myRe = / \? * ([^ =] *) = ([^ & Amp; *) /; Var myArray; While ((myArray = myRe.exec ("? Page = 3 and name = Alex")! == faucet) {for (var i = 1; i & lt; myArray.length; i ++) {Warning (myArray [I]); }}   

In addition, you regex incorrect, it definitely requires a g switch, but I had to work using this regex: var regex = / ([^ = & amp;?] +) = ([^ & Amp;] +) / g;

See live examples:

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -