wordword word\";
$str = preg_replace(\"/word(?!([^<]+)?>)/i\",\"repl\",$str);
echo $str;
To translate that regex for use in Java, all you have to do is get rid of the /
delimiters and change the trailing i
to an inline modifier, (?i)
. But it's not a very good regex; I would use this instead:
(?i)word(?![^<>]++>)
According to RegexBuddy's Debug feature, when it tries to match the word
in , the original regex requires 23 steps to reject it, while this one takes only seven steps. The actual Java code is
str = str.replaceAll("(?i)word(?![^<>]++>)", "repl");