// Regex - match anything except specific string echo preg_replace('/(?!.*(red|green|blue).*)(.*(YOUR_REGEXP).*)/', 'dog', $string); // http://stackoverflow.com/questions/16930563/regex-match-anything-except-specific-string