3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "This is <a href=\"http://foo.com\">This is #foo</a>.\nSimple #html-stuff text <a href=\"http://foobar.com#baz\">#simple</a>. \n<span class=\"simple\">simple #simple text text</span>"; $str = preg_replace('/(?!<a[^<>]*>[^#]+)#(\b[-_\w]+\b)(?![^<]*<\/a>)/', '<a href="/tags/$1">#$1</a>', $str); echo $str;

preferences:
44.44 ms | 402 KiB | 5 Q