wordword word\"; $str = preg_replace(\"/word(?!([^<]+)?>)/i\",\"repl\",$str); echo $str;
Before providing a further answer, are you trying to parse an html document? If so, don't use regexes, use an html parser.