Last active
May 14, 2018 13:26
-
-
Save jasp402/32242b429693e200dca6e7d07f280092 to your computer and use it in GitHub Desktop.
JavaScript - Regex, (Clear String)
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
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