Skip to content

Instantly share code, notes, and snippets.

@ryanve
Created May 9, 2017 02:11
Show Gist options
  • Save ryanve/004dcaecf1fe4835345385b4d1500c78 to your computer and use it in GitHub Desktop.
Save ryanve/004dcaecf1fe4835345385b4d1500c78 to your computer and use it in GitHub Desktop.
JavaScript regex to blacklist words
/^(?!(corn|bread)$).+/.test('corn') // false (blacklisted)
/^(?!(corn|bread)$).+/.test('bread') // false (blacklisted)
/^(?!(corn|bread)$).+/.test('cornbread') // true (not blacklisted)
/^(?!(corn|bread)$).+/.test('corndog') // true (not blacklisted)
/^(?!(corn|bread)$).+/.test('read') // true (not blacklisted)
@ryanve
Copy link
Author

ryanve commented May 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment