<head>\r\n<title>tou </title>\r\n</head>\r\n<a herf="www.jctrans.com"\r\ntarget=_blank></a>
上面的这个表达式,如果我只想过滤掉标签内的回车换行(\r\n),标签外的回车换行保留,正则表达式,咋写啊?
上面的这个表达式,如果我只想过滤掉标签内的回车换行(\r\n),标签外的回车换行保留,正则表达式,咋写啊?
解决方案 »
- winform 设置鼠标样式 我设置成一张图片了但是 最好不要把原本的那个箭头隐藏。求大神
- 怎么我的VS少了一堆东西
- 请教高手,一个字符串排序问题
- 自定义控件,扩展了IPostBackDataHandler接口但是却不执行LoadPostData方法??
- 如何用c#做一个文件检索动态显示的功能
- 执行存储过程中,如何获取其返回的数据集!!!
- =====50分求高手来看看这个问题,用.net实现横向图片分页
- 谁见过报这样的错误:"没有可用于当前位置的源代码。"
- Clone报错内存不足【winform】
- 程序生成出错过后,即使代码已经正确也会出错,以下提示:未能写入输出文件“路径\程序.exe”--“拒绝访问。 ”
- 请教几个小问题vb.net语句 转 c#的
- 静态方法这样写为什么不对
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");
string result=System.Text.RegularExpressions.Regex.Replace("你的字符串",@"(?<=<[^\r\n><]*)[\r\n]","");
过滤出来的字符串为<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>
就差一点了
那就:
string result=System.Text.RegularExpressions.Regex.Replace("你的字符串",@"(? <= <[^\r\n><]*)\r\n","");
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>
*/