日期:2014-05-17  浏览次数:20546 次

正则表达式如何写[/表情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