<?php $input = [ '<p>test:</p>', '<p>test: foo</p>', '<p>foo:</p>', '<p>: foo</p>', '<p>test </p><p>:</p>', ]; foreach ($input as $val) { echo(preg_replace('/(<p>)([^<]+?:)(.*)/', '$1<strong>$2</strong>$3', $val)); echo("\n"); }
You have javascript disabled. You will not be able to edit any code.