Skip to content

Instantly share code, notes, and snippets.

@kneath
Created December 10, 2009 08:29
Show Gist options
  • Save kneath/253205 to your computer and use it in GitHub Desktop.
Save kneath/253205 to your computer and use it in GitHub Desktop.
// HTML escapes `string`
var patterns = [[/&/g, "&amp;"], [/</g, "&lt;"], [/>/g, "&gt;"], [/"/g, "&quot;"]]
for(pattern in patterns)
string = string.replace(pattern[0], pattern[1]);
// for the line obsessed
for([[/&/g, "&amp;"], [/</g, "&lt;"], [/>/g, "&gt;"], [/"/g, "&quot;"]] in patterns); string = string.replace(pattern[0], pattern[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment