Skip to content

Instantly share code, notes, and snippets.

@anhang
Created August 3, 2011 22:47
Show Gist options
  • Select an option

  • Save anhang/1124043 to your computer and use it in GitHub Desktop.

Select an option

Save anhang/1124043 to your computer and use it in GitHub Desktop.
HTML Params parser
// Super basic html parser written with regex.
// Experimental and untested
function parseParams(str){
return JSON.parse("{"+
str.replace(/.+?=.+?(,|$)/g,
function(part){ return part.replace(/(.+)(=)([^,]+)(,*)/,
function(x, key, eq, val, com){return ["\"",key,"\"",":","\"",val,"\"",com].join('');})
}) +"}";
);
}
// str = "id=MY_ID,title=MY_TITLE"
// parseParams(str)
// Object
// id: "MY_ID"
// title: "MY_TITLE"
// __proto__: Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment