Created
August 3, 2011 22:47
-
-
Save anhang/1124043 to your computer and use it in GitHub Desktop.
HTML Params parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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