日期:2014-05-18  浏览次数:20825 次

会正则表达式的进,求一正则表达式
求一正则表达式如下:

string   Text   =   " <a   href= 'abc '> abc </a> ";

“ <> ”里的abc就不替换,非 <> 里的abc就替换成我要的字符,
说白了,就说只替换html里的Text匹配字符而不替换html的匹配字符,要以是否“ <> ”内来判断是否Text还是HTML,十分感激。

------解决方案--------------------
(? <!\> )abc(?!\ <)
------解决方案--------------------
> ([^ <]*) < 替换为 > 你想要的内容 <


你的表达能力有待提高啊....
------解决方案--------------------
(? <= <a[^> ]*> )[^ <](?= </a> )
------解决方案--------------------
用委托

string Text = "the abc <tr title= 'abc '> is <td> <a href= 'abc '> abc </a> </td> a </tr> test ";
string result = Regex.Replace(Text, @ "^[^ <> ]*|> [^ <> ]* <|[^ <> ]*$ ", new MatchEvaluator(regReplace));


private string regReplace(Match m)
{
return m.Value.Replace( "abc ", "your text ");
}