3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $pattern = '~(?:(?<=<p class="code">\v)|(?!\A)\G\v*)^((?>(?!</p>)\V)*)(\v)~m'; $str = ' <p>hello see my css below</p> <p class="code"> h1 { font-size:10px font-color:#FFF } h2 { font-size:10px font-color:#FFF } </p> <p>123</p> <p class="code"> 1 2 3 </p>'; $str = preg_replace($pattern, '<code>\1</code>\2', $str); echo $str;
Output for 5.3.19 - 5.3.29, 5.4.9 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<p>hello see my css below</p> <p class="code"> <code>h1 { </code> <code>font-size:10px</code> <code>font-color:#FFF</code> <code>}</code> <code>h2 { </code> <code>font-size:10px</code> <code>font-color:#FFF</code> <code>}</code> </p> <p>123</p> <p class="code"> <code>1</code> <code>2</code> <code>3</code> </p>
Output for 4.4.9, 5.2.4 - 5.3.18, 5.4.0 - 5.4.8
Warning: preg_replace(): Compilation failed: lookbehind assertion is not fixed length at offset 25 in /in/uuagr on line 25
Output for 4.3.0 - 4.4.8, 5.0.0 - 5.2.3
<p>hello see my css below</p> <p class="code"> h1 { font-size:10px font-color:#FFF } h2 { font-size:10px font-color:#FFF } </p> <p>123</p> <p class="code"> 1 2 3 </p>