I am trying to parse !Name=John OR !Address="1234 Place Lane" AND tall in Javascript, extracting the "parameters" as key/value if they have a ! in front and otherwise as a simple string. Example code is below:
 1 var input = '!Name=John OR !Address="1234 Place Lane" AND tall';
 2 var params = input.match(/.../g); // <--??  what is the proper regex?
 3 var i = params.length;
 4 while(i--) {
 5   params[i] = params[i].replace(/"/g."");
 6   if( params[i].indexOf("!")==0 ) {
 7      params[i] = params[i].substring(1);
 8        // Address=1234 Place Lane
 9      var position = params[i].indexOf('=');
10      var key = params[i].substring(0,position);
11      var value = params[i].substring(1+position);
12      params[i] = {"key": key, "value": value}; 
13        // {key: "Address", value: "1234 Place Lane"}
14        // {key: "Name", value: "John"}
15   }
16 }
17 // params = [ {key:"Name",value:"John"}, "OR", {...}, "AND", "tall" ];
Related question: javascript split string on space or on quotes to array
 
     
    
