Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active November 10, 2015 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WebReflection/54a3067c1df07f382faf to your computer and use it in GitHub Desktop.
Save WebReflection/54a3067c1df07f382faf to your computer and use it in GitHub Desktop.
no swear
var terms = ['shit', 'fuck'];
var re = RegExp('\\b(?:' + terms.join('|') + ')\\b', 'i');
var hasBadWords = function (str) { return re.test(str); };
hasBadWords("hit me duck"); // false
hasBadWords("holy shit"); // true
hasBadWords("My assistant couldn't find shitake mushrooms."); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment