// Regex to ignore escaped quotes within quotes echo preg_replace('/"[^"\\]*(?:\\.[^"\\]*)*"/', 'dog', $string); // http://stackoverflow.com/questions/5695240/php-regex-to-ignore-escaped-quotes-within-quotes