Skip to content

Instantly share code, notes, and snippets.

@townofdon
Created May 26, 2020 13:16
Show Gist options
  • Save townofdon/55ad0291c830ef893b1333b2ca317b09 to your computer and use it in GitHub Desktop.
Save townofdon/55ad0291c830ef893b1333b2ca317b09 to your computer and use it in GitHub Desktop.
filter-bad-words.js
const badwords = [
'frick',
'fark',
'dern',
'shiz'
].join('|');
const badEmojis = [
'\\u{1F4A9}', // pile of poo
'\\u{1F595}' // middle finger
].join('|');
const BADWORDS_REGEX = new RegExp(`(\\b(${badwords})\\b)|(${badEmojis})`, 'igu');
function filterProfanity (text) {
return text.replace(BADWORDS_REGEX, '****');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment