Skip to content

Instantly share code, notes, and snippets.

@afulsamet
Last active March 4, 2021 06:07
Show Gist options
  • Save afulsamet/72c7d40ebc5da267c397e32f4a72b15b to your computer and use it in GitHub Desktop.
Save afulsamet/72c7d40ebc5da267c397e32f4a72b15b to your computer and use it in GitHub Desktop.
Censor bad words with JavaScript
const Regex = {
BadWords: /(bad word|can't censor me)/g
}, IString = "hey, i'm a bad word and you can't censor me";
IString.replace(new RegExp(Regex.BadWords), RString => Array.from(RString).map(() => "*").join(String()))
// Output: "hey, i'm a ******** and you ***************"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment