JavaScript regex for blacklisting words [duplicate]
问题 This question already has answers here : Regex: match everything but specific pattern (7 answers) Closed 2 years ago . I'm trying to write a regex to blacklist certain words. I'm able to create a whitelist like /^(carrots|onions|corn)$/ but how would I convert that into a blacklist? Edit: To clarify, I'm matching this blacklist against a whole string. For example "corndog" should be allowed. I want the regex equivalent of blacklistArray.indexOf(word) === -1 回答1: Use negative lookahead: ^(?!.*