Skip to content

Instantly share code, notes, and snippets.

@anhang
Created August 3, 2011 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhang/1124043 to your computer and use it in GitHub Desktop.
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