Regex with exception of particular words

cpu-word, exception, regex

Solution

If you really want to do this with a single regular expression, you might find lookaround helpful (especially negative lookahead in this example). Regex written for Ruby (some implementations have different syntax for lookarounds):

rx = /^(?!apple$|orange$|juice$)/

Problem

I have problem with regex. I need to make regex with an exception of a set of specified words, for example: apple, orange, juice. and given these words, it will match everything except those words above. ``` applejuice (match) yummyjuice (match) yummy-apple-juice (match) orangeapplejuice (match) orange-apple-juice (match) apple-orange-aple (match) juice-juice-juice (match) orange-juice (match) apple (should not match) orange (should not match) juice (should not match) ```

Original source