Try this /^((?!except=yes).)*$/
. Refer to this post for further details.
2.0.0-p648 :009 > regex = /^((?!except=yes).)*$/
=> /^((?!except=yes).)*$/
2.0.0-p648 :010 > "www.example.com".match regex
=> #<MatchData "www.example.com" 1:"m">
2.0.0-p648 :011 > "www.example.com/".match regex
=> #<MatchData "www.example.com/" 1:"/">
2.0.0-p648 :012 > "www.example.com/?except=yes".match regex
=> nil
2.0.0-p648 :013 > "www.example.com/?test=true&except=yes".match regex
=> nil
2.0.0-p648 :014 > "www.example.com/?test=true&except=yes&foo=bar".match regex
=> nil
2.0.0-p648 :015 > "www.example.com/foo/bar/?except=yes".match regex
=> nil
2.0.0-p648 :016 > "www.example.com/?test=true&except=yesyes&foo=bar".match regex
=> nil
Edit
In order to match the last string(which contains except=yesyes
), use the following regex. /^((?!except=yes\b).)*$/
The only difference is \b
, which matches word boundary such as whitespace, punctuations.
> /^((?!except=yes\b).)*$/.match "www.example.com"
=> #<MatchData "www.example.com" 1:"m">
> /^((?!except=yes\b).)*$/.match "www.example.com/"
=> #<MatchData "www.example.com/" 1:"/">
> /^((?!except=yes\b).)*$/.match "www.example.com/?except=yes"
=> nil
> /^((?!except=yes\b).)*$/.match "www.example.com/?test=true&except=yes"
=> nil
> /^((?!except=yes\b).)*$/.match "www.example.com/?test=true&except=yes&foo=bar"
=> nil
> /^((?!except=yes\b).)*$/.match "www.example.com/foo/bar/?except=yes"
=> nil
> /^((?!except=yes\b).)*$/.match "www.example.com/?test=true&except=yesyes&foo=bar"
=> #<MatchData "www.example.com/?test=true&except=yesyes&foo=bar" 1:"r">