当前位置: 代码迷 >> ASP.NET >> 正则表达式怎么写[/表情1]jdf[/表情2]jdfl转为<img src=face/1.gif>jdf<img src=face/2.gif>jdfl
  详细解决方案

正则表达式怎么写[/表情1]jdf[/表情2]jdfl转为<img src=face/1.gif>jdf<img src=face/2.gif>jdfl

热度:2640   发布时间:2013-02-25 00:00:00.0
正则表达式如何写[/表情1]jdf[/表情2]jdfl转为<img src=face/1.gif>jdf<img src=face/2.gif>jdfl
[/表情1]jdf[/表情2][/表情34]jdflksjflsjlsjf
转换为
<img src=face/1.gif>jdf<img src=face/2.gif><img src=face/34.gif>jdflksjflsjlsjf
正则表达式如何写

------解决方案--------------------------------------------------------
C# code
            string source = "[/表情1]jdf[/表情2][/表情34]jdflksjflsjlsjf";            Regex reg = new Regex(@"(?is)(/表情)(\d+)(])");            source = reg.Replace(source, "<img src=face/$2.gif>");
------解决方案--------------------------------------------------------
C# code
   string test = "[/表情1]jdf[/表情2][/表情34]jdflksjflsjlsjf";                test = Regex.Replace(test, @"\[/\D+(\d+)\]", "<img src=face/$1.gif>");//<img src=face/1.gif>jdf<img src=face/2.gif><img src=face/34.gif>jdflksjflsjlsjf