Skip to content

Instantly share code, notes, and snippets.

@jasp402
Last active May 14, 2018 13:26
Show Gist options
  • Save jasp402/32242b429693e200dca6e7d07f280092 to your computer and use it in GitHub Desktop.
Save jasp402/32242b429693e200dca6e7d07f280092 to your computer and use it in GitHub Desktop.
JavaScript - Regex, (Clear String)
clearStr(str) {
const corrections = {
'&': '',
'\/': '',
'\\': '',
'#': '',
',': '',
'+': '',
'(': '',
')': '',
'$': '',
' ': '_',
'~': '',
'%': '',
'.': '',
'\'': '',
'\"': '',
':': '',
'?': '',
'<': '',
'>': '',
'{': '',
'}': '',
'\n': '',
'*': ''
};
const regex = new RegExp("[" + Object.keys(corrections).join("") + "]", "g");
return str.replace(regex, character => corrections[character]);
};
/* Source: http://defindit.com/ascii.html */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment