3v4l.org

run code in 300+ PHP versions simultaneously
<?php $txt = 'dog blah crocodile blah dog blah cat blah crocodile blah dog blah crocodile blah dog blah cat blah dog blah cat blah crocodile blah dog blah crocodile blah mice blah cat blah crocodile'; echo preg_replace('/(?:dog|mice)(?:(?!dog|mice|cat).)* \Kcrocodile(?= (?:(?!dog|mice|cat).)* (?:dog|mice))/', 'replacement', $txt);

preferences:
69.2 ms | 402 KiB | 5 Q