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 Use negative lookahead: ^(?!.*(?:carrots|onions|corn)) 来源: https://stackoverflow.com/questions/43641351/javascript-regex-for-blacklisting