当前位置: 代码迷 >> ASP.NET >> 正则表达式~
  详细解决方案

正则表达式~

热度:9007   发布时间:2013-02-25 00:00:00.0
求一个正则表达式~~
<table   style= "border-collapse:   collapse "   bordercolor= "#111111 "   cellspacing= "0 "   cellpadding= "0 "   width= "610 "   border= "1 "   align= "center ">
    <tr>
        <td>       </td>
    </tr>
</table>
</P>
<IMG   title= "123 "   src=\ "http://192.19.19.43/test.gif "   align=left>
</P>
<P> &nbsp;456 </P>

结果:123456

——————————————
忽略所有html标记     除 <IMG> 的title值




------解决方案--------------------------------------------------------
try

string result = Regex.Replace(yourStr, @ " <img[^> ]*title=([ ' " "]?)(? <title> [^ ' " "]*)\1?[^> ]*> ", "${title} ", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @ "( <[^> ]*> |\s|&nbsp;) ", " ");

------解决方案--------------------------------------------------------
or

string yourStr = ..............;
string result = Regex.Replace(yourStr, @ "( <img[^> ]*title=([ ' " "]?)(? <title> [^ ' " "]*)\1?[^> ]*> | <[^> ]*> |\s|&nbsp;) ", "${title} ", RegexOptions.IgnoreCase);