re = /^(?!.*\b(?:dirty|rotten)\b).*?\b(?:red|green|yellow)\b.*\b(?:apple|peach|pear)\b.*$/m
str = ' I have an green apple I have a yellow peach I have red and green apples
I have a dirty red apple I have a green peach that is dirty I have a yellow dirty apple
This is a green pear
This is a rotten green pear
This is pear, a green pear
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html