开发者

Regular expression to match time and IRC-Nick

开发者 https://www.devze.com 2023-03-21 04:47 出处:网络
I\'m not very experie开发者_如何学运维nced in regular expressions and I tried a lot to match a string like this:

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&lt;DJ_Bjarne&gt;</strong>

with a regex that works in PHP. Thank you.


$post = "16:02 &lt; DJ_Bjarne&gt; hello mate!";
preg_replace("/(.*?&gt;)/", "<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 &lt;DJ_Bjarne&gt;';
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

0

精彩评论

暂无评论...
验证码 换一张
取 消