Reputation: 82
I have a string:
User_TimeStamp=20120712201112&[email protected]&resetCode=**uNcoHR9O3wAAB46xw**&reset=true
I tried and Googled a lot to get the highlighted text. Basically I want a JavaScript regex to get all characters in between resetCode=
and &reset=true
.
Any help regarding this is highly appreciated.
Thanks
Upvotes: 0
Views: 62
Reputation: 206121
You can do something more 'readable':
retrieveDesired = User_TimeStamp.split('=')[3].split('&')[0];
Upvotes: 1
Reputation: 16025
Try this code where you're looking for the resetCode
variable
var resetCodeValue;
var s = window.location.split('&');
for(var k in s) { var pair = s[k].split('=');
if (pair[0] == 'resetCode'){
resetCodeValue = pair[1];
}
}
Upvotes: 1
Reputation: 673
Two ways:
resetCode=([^&]*)
&
then iterate through each string and split on =
comparing the first string to resetCode
and return the second string when you find it. Upvotes: 1
Reputation:
why not just use this handy function to get the value of resetCode
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
document.write(getUrlVars()["resetCode"]);
Upvotes: 0