Regular expression for a string containing one word but not another

This should do it:

^(?!.*details\.cfm).*selector=size.*$

^.*selector=size.*$ should be clear enough. The first bit, (?!.*details.cfm) is a negative look-ahead: before matching the string it checks the string does not contain “details.cfm” (with any number of characters before it).

Leave a Comment