$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
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php