I am using Javascript and trying to break out query string variables from their values. I made a regex that works just fine IF there are no other ampersands except for denoting variables, otherwise the data cuts off at the ampersand.
example: ajax=10&a=test&b=cats & dogs
returns a = "test"
, b = "cats "
I cannot encode the ampersands before the string is made due to the nature of this project and the inefficiency with encoding/replacing characters in hundreds of locations upon entry.
What this piece of code should ultimately do is turn the querystring ajax=10&a=cats & dogs
into ajax=10&a=cats%20%26%20dogs
list = [ 'ajax','&obj','&a','&b','&c','&d','&e','&f','&g','&h','&m' ];
ajax_string = '';
for (var i=0, li=list.length; i<li; i++) {
variables = new RegExp(list[i] +"=([^&(.+)=]*)");
query_string = variables.exec(str);
if (query_string != null) {
alert(query_string);
}
}