2

谁能帮我写一个正则表达式,结果如下,用html标签替换bbcode,因为这里我想替换[b][/b]<strong></strong>

所以这:

 "fsdfs [b]abc[/b] dddfs [b]abc[/b] fdsfdsfs [b]abcfsdfs" 

变成:

 "fsdfs <strong>abc</strong> dddfs <strong>abc</strong> fdsfdsfs [b]abcfsdfs"

以下正则表达式是否有助于解决此问题?

 string result = Regex.Replace(s, @"\[b\](.*?)\[\/b\]", @"\<stront\>(.*?)\<\/strong\>");
4

1 回答 1

5

以下应该有效:

string s = "fsdfs [b]abc[/b] dddfs [b]abc[/b] fdsfdsfs [b]abcfsdfs";
string result = Regex.Replace(s, @"\[b\](.*?)\[/b\]", @"<strong>$1</strong>");

示例:http: //ideone.com/xwP1EL

于 2013-04-10T23:34:31.327 回答