<head>\r\n<title>tou </title>\r\n</head>\r\n<a herf="www.jctrans.com"\r\ntarget=_blank></a>
上面的这个表达式,如果我只想过滤掉标签内的回车换行(\r\n),标签外的回车换行保留,正则表达式,咋写啊?

解决方案 »

  1.   

    就是过滤掉像这里面的回车换行<a herf="www.jctrans.com"\r\ntarget=_blank> </a>,其他的回车换行不变
      

  2.   

    head>\r\n <title>tou </title>\r\n </head>\r\n ,这样的保留
      

  3.   


    string x = "<head>\r\n <title>tou </title>\r\n </head>\r\n <a herf=\"www.jctrans.com\"\r\ntarget=_blank> </a>";
    x = Regex.Replace(x, "(<[\\w\\W]*?)\\r\\n([\\w\\W]*?>)", "$1 $2");
      

  4.   

    TRY......
    string result=System.Text.RegularExpressions.Regex.Replace("你的字符串",@"(?<=<[^\r\n><]*)[\r\n]","");
      

  5.   

    string result=System.Text.RegularExpressions.Regex.Replace("你的字符串",@"(?<=<[^\r\n><]*)[\r\n]","");,这个没有替换掉\n,只替换掉了\r啊
      

  6.   

    使用x = Regex.Replace(x, "(<[\\w\\W]*?)\\r\\n([\\w\\W]*?>)", "$1 $2");
    过滤出来的字符串为<head> <title>tou </title> </head>\r\n<a herf=\"www.jctrans.com\" target=_blank></a>使用string result=System.Text.RegularExpressions.Regex.Replace("你的字符串",@"(?<=<[^\r\n><]*)[\r\n]","");
    过滤字符串为<head>\r\n<title>tou </title>\r\n</head>\r\n<a herf=\"www.jctrans.com\" \ntarget=_blank></a>
    就差一点了
      

  7.   

    \r\n肯定同时出现吗?
    那就:
    string result=System.Text.RegularExpressions.Regex.Replace("你的字符串",@"(? <= <[^\r\n><]*)\r\n","");
      

  8.   

    string result=System.Text.RegularExpressions.Regex.Replace("你的字符串",@"(? <= <[^\r\n><]*)\r\n","");这个可以过滤掉我给的那个字符串,但是如果一个标签内出现多个\r\n的话就不好用了,我想要一个只要回车换行出现在标签内,不论多少次,在那个位置,一样能过滤,比如<head>\r\n <title>tou </title>\r\n </head>\r\n <a\r\n herf="www.jctrans.com"\r\ntarget=_blank\r\n> </a> <font \r\n size=12></font>过滤之后是<head>\r\n <title>tou </title>\r\n </head>\r\n <a herf="www.jctrans.com" target=_blank> </a> <font size=12></font>这样的形式
      

  9.   

    就是过滤掉像这里面的回车换行<a herf="www.bjdragon.com"\r\ntarget=_blank> </a>,其他的回车换行不变
      

  10.   


                string str = "<head>\r\n<title>tou </title>\r\n</head>\r\n<a herf=\"www.jctrans.com\"\r\ntarget=_blank></a>";
                string result = Regex.Replace(str, @"(?is)(?<=<[^>]*?)\r\n", delegate(Match m)
                {
                    if (m.Success)
                        return "";
                    else
                        return m.Value;
                });
                Response.Write(result);
    /*
    <head>
    <title>tou </title>
    </head>
    <a herf="www.jctrans.com"target=_blank></a>
    */