I have ref=Apple
and my current regex is
var regex = /ref=(.+)/;
var ref = regex.exec(window.location.href);
alert(ref[0]);
but that includes the ref=
now, I also want to stop capturing characters if a & is at the end of the ref param. cause ref may not always be the last param in the url.
Use
ref[1]instead.This accesses what is captured by group 1 in your pattern.
Note that there’s almost certainly a better way to do key/value parsing in Javascript than regex.
References