开发者

regex to remove bbcode tags with atrributes

I've got a number of bbcode tags that have phpbb attributes (5 digit value - assuming text color or something). They look like this in the text:

This is [b:31747]bold[/b:31747] text and so is [b:17171]this[/b:17171].

I cannot get a regex working that finds bracket+b+colon+any_combo_of_5_digits+end_bracket and lets me replace it with corresponding html. Using php's preg_replace() fun开发者_JAVA技巧ction, if it makes a difference.


This should work with both opening and closing tags for any type of tag:

$string = preg_replace("/\[(\/?[a-zA-Z]+):[\d]{5}\]/is", "<$1>", $string);


This would replace bold, underline and italic tags.

$new_text = preg_replace('~\[(/?[bui]):\d+\]~is', '<$1>', $text);
echo $new_text; // This is <b>bold</b> text and so is <b>this</b>.


The regular expression you need is:

\[/?b:\d{5}]


preg_replace("/\[\/?b:[0-9]*?\]/","","[b:17171]this[/b:17171]");

http://ideone.com/fDCZM

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜