现在做了一个简易的留言板系统
求将"[url=http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=56eedeb3-d039-46aa-8bdd-33a5c45be40e]"转化为<a href="http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=56eedeb3-d039-46aa-8bdd-33a5c45be40e" target="_blank">的正则表达式。。
或者直接提供这种替换的完整代码也可以
谢谢!附:自己写的一部分。#region 过滤字符串,使输入字符串能够完美显示在网页上 Filter2(string s)
        /// <summary>
        /// 过滤字符串,使输入字符串能够完美显示在网页上(包含论坛字符)
        /// </summary>
        /// <param name="s">要转化的字符串</param>
        /// <returns></returns>
        public static string Filter2(string s)
        {
            //将&字符转义
            s = s.Replace("&", "&amp;");
            //将<字符转义
            s = s.Replace("<", "&lt;");
            //将>字符转义
            s = s.Replace(">", "&gt;");
            //将"字符转义
            s = s.Replace("\"", "&quot;");
            //将空格字符转义
            s = s.Replace(" ", "&nbsp;");
            s = s.Replace(" ", "&nbsp;");
            //将换行字符转义
            s = s + "<p>";
            s = s + "</p>";
            s = s.Replace(Environment.NewLine, "</p><p>");
            //转义论坛图片符号
            s=Regex.Replace(s, "\\[img\\]", "<img alt=\"\" src=\"");
            s = Regex.Replace(s, "\\[/img\\]", "\"/>");
            //转义论坛粗体符号
            s = Regex.Replace(s, "\\[bold\\]", "<span style=\"font-weight:bold;\">");
            s = Regex.Replace(s, "\\[/bold\\]", "</span>");
            //转义论坛链接符号
            //这里不知道怎么写
            s = Regex.Replace(s, "\\[/url\\]", "</a>");
            return s;
        }
        #endregion在线等

解决方案 »

  1.   

    思路先把路径提取出来,而后直接replace
      

  2.   

    try...string test = "[url=http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=56eedeb3-d039-46aa-8bdd-33a5c45be40e]";
    string result = Regex.Replace(test, @"(?i)\[url=([^\]]*)\]", @"<a href=""$1"" target=""_blank"">");
    richTextBox2.Text = result;
      

  3.   

    提取路径
    static void Main(string[] args)
            {
                string mm = @"[url=http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=56eedeb3-d039-46aa-8bdd-33a5c45be40e]";
                Regex m = new Regex(@"\[url=(.*)\]");
                if (m.Match(mm).Success)                      
                      Console.WriteLine(m.Match(mm).Value);
            }
      

  4.   

    这个问题为什么要搞得那么麻烦呢,把[url=之后的部分全部取出来,去掉最后的],然后添加到<a herf="" tar……中来不就完了吗?