如何用正则表达式将
"[type=type1]abcd123中国[/type][type=type2]abcd中国123[/type]"
替换为
"<div>abcd123中国</div><table><tr><td>abcd中国123</td></tr></table>"

解决方案 »

  1.   

    string str = @"[type=type1]abcd123中国[/type][type=type2]abcd中国123[/type]";
            Regex reg = new Regex(@"\[type=type1\]([\s\S]*?)\[/type\]\[type=type2\]([\s\S]*?)\[/type\]");        str = reg.Replace(str,"<div>$1</div><table><tr><td>$2</td></tr></table>");
            Response.Write(Server.HtmlEncode(str));
      

  2.   

    cpp2017(慕白兄) 的应该是正解!
    我不会呀!来学学!
      

  3.   

    又来晚了
    不过楼主给出的只是一个实例,是否有什么特殊情况,如果全是如楼主所给的例子,那用string的Replace()方法就完全可以做到,效率要比正则高的