如
<div id= "ttt "> xxx </div>
<div id= "ccc "> ab </div>
用正则换成
<div id= "ttt "> xxx </div> <br>
<div id= "ccc "> ab </div>
最好是基于.net的实现,js也行
万分感谢!
------解决方案--------------------------------------------------------
基本是如下实现,具体标记可能写的有问题就是单词写错啦哈哈,手写的不确定。
document.getElmentByid( "id ").innerHtml.replace( " ", " ")
------解决方案--------------------------------------------------------
先匹配整个 Html 的 Tag 和里面的内容,分在不同的捕获组里。
然后将内容中的空格替换为
最后重新组合字符串。
string ResultString = null;
try {
Regex RegexObj = new Regex( " <(? <tag> [A-Z][A-Z0-9]*)[^> ]*> (? <content> .*?) </\\k <tag> > ",
RegexOptions.Singleline | RegexOptions.IgnoreCase);
ResultString = RegexObj.Match(html).Groups[ "content "].Value;
ResultString = ResultString.Replace( " ", " ");
string dest = string.Format( " <{0}> {1} <\{0}> ", RegexObj.Match(html).Groups[ "tag "].Value, ResultString);
// 重新合并字符串
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
------解决方案--------------------------------------------------------
string str = @ " <div id= " "ttt " "> xxx </div> <div id= " "ccc " "> ab </div> "; System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex( "( <[^> ]*?> )([^> ]*?)( </[^> ]*?> ) "); str = reg.Replace(str, new System.Text.RegularExpressions.MatchEvaluator(this._Replace)); Response.Write(str); string _Replace(System.Text.RegularExpressions.Match m) { return m.Result( "$1 ") + m.Result( "$2 ").Replace( " ", " ") + m.Result( "$3 "); }