3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sampleString = "<a href='{{url}}'>Link</a> <p>This text {{url}} will not get replaced</p> <a href='{{url}}' download='true'>Another Link</a>"; $regex = "/(?<=href=')()(?={{url}}.*>)/"; $replaced = preg_replace($regex, "https://myurl.com?redirect=\1", $sampleString); echo $replaced;

preferences:
36.27 ms | 405 KiB | 5 Q