Skip to content

Instantly share code, notes, and snippets.

@mbifulco
Created August 25, 2015 19:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbifulco/a242f67cb03caf7fca3d to your computer and use it in GitHub Desktop.
Save mbifulco/a242f67cb03caf7fca3d to your computer and use it in GitHub Desktop.
jquery dictionary
//characters we want to replace:
/*
< with &lt;
> with &gt;
*/
var jsob =
{
"<" : "&lt;",
">" : "&gt;"
};
var replaceSpecialCharacters = function(input, dictionary)
{
var res = input;
$.each(dictionary, function(key, value ){
var find = key;
var replace = value;
find = new RegExp(find,"igm");
res = res.replace(find,replace);
});
return res;
};
console.log(replaceSpecialCharacters("<em>hello</em>", jsob));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment