wordword word\";
$str = preg_replace(\"/word(?!([^<]+)?>)/i\",\"repl\",$str);
echo $str;
Use the String.replaceAll() method:
class Test {
public static void main(String[] args) {
String str = "word wordword word";
str = str.replaceAll("word(?!([^<]+)?>)", "repl");
System.out.println(str);
}
}
Hope this helps.