Reputation: 9
This question here helped me how to do an exception: Regex with exception of particular words
Basically, rx = /^(?!apple$|orange$|banana$)/
would match everything but apple, orange and banana. But now I need to know how to do an exception for an exception.
rx = /^(?!.*$)/
I believe this would ignore everything, but what should I add to make it match nothing BUT some pre-defined words, like banana and apple?
Upvotes: 0
Views: 76
Reputation: 359966
The opposite of the opposite of x
is simply x
:
/^(apple|orange|banana)$/
The above regex only accepts input which exactly matches apple
, orange
, or banana
.
Upvotes: 1