Created
August 3, 2011 22:47
-
-
Save anhang/1124043 to your computer and use it in GitHub Desktop.
Revisions
-
anhang revised this gist
Aug 4, 2011 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,9 @@ 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('');}) }) +"}"); } -
anhang revised this gist
Aug 3, 2011 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,8 +6,7 @@ function parseParams(str){ 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" -
anhang created this gist
Aug 3, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ // 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