I cannot find out the regex to get param value from the part of query string:
I need to send parameter name to a method and get parameter value as result for string like
"p=1&qp=10"
.
I came up with the following:
function getParamValue(name) {
var regex_str = "[&]" + name + "=([^&]*)";
var regex = new RegExp(regex_str);
var results = regex.exec(my_query_string);
// check if result found and return results[1]
}
My regex_str now doesn't work if name = 'p'
. if I change regex_str
to
var regex_str = name + "=([^&]*)";
it can return value of param 'qp'
for param name = 'p'
Can you help me with regex to search the beginning of param name from right after '&'
OR from the beginning of a string?