Regular expression to match time and IRC-Nick
I'm not very experie开发者_如何学运维nced in regular expressions and I tried a lot to match a string like this:
16:02 <DJ_Bjarne>
with a regex, but I didn't get any working result. I want this to be replaced by
<strong>16:02<DJ_Bjarne></strong>
with a regex that works in PHP. Thank you.
$post = "16:02 < DJ_Bjarne> hello mate!";
preg_replace("/(.*?>)/", "<strong>$1</strong>", $post);
This should do what you need:
$string = preg_replace('/[0-9]{1,2}:[0-9]{1,2} <.*?>/', '<strong>$0</strong>', $string);
Try:
preg_replace('/[\d]{2}:[\d]{2} [\<][\w]+[\>]/', '<strong>${0}</strong>', $line)
y Tooo complecated
$text = '16:02 <DJ_Bjarne>';
echo $text = preg_replace("/\A/",'<strong>',$text);
//echo "<textarea>";echo $text;echo "</textarea>";
$text = preg_replace("/\Z/",'</strong>',$text);
echo "<textarea>";echo $text;echo "</textarea>";
its simple easy to understand, refference
精彩评论