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

高难度正则匹配--高分猎头
<![if !vml]>
<span style='mso-ignore:vglayout;position:
absolute;z-index:7;left:117px;top:103px;width:28px;height:12px'>
<img width=28 height=12 src="民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif" v:shapes="_x0000_s1032">
</span>
<![endif]>


<![if !vml]>
<img width=28 height=12 src="民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif" v:shapes="_x0000_s1032">
<![endif]>

用正则试处理后(替换)变成
[img width=28 height=12 src="民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif"/]

------解决方案--------------------
HTML code

<![if !vml]> 
<span style='mso-ignore:vglayout;position: 
absolute;z-index:7;left:117px;top:103px;width:28px;height:12px'> 
<img width=28 height=12 src="民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif" v:shapes="_x0000_s1032"> 
</span> 
<![endif]> 


<![if !vml]> 
<img width=28 height=12 src="民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif" v:shapes="_x0000_s1032"> 
<![endif]> 

<!--变化成-->

<![if !vml]> 
<span style='mso-ignore:vglayout;position: 
absolute;z-index:7;left:117px;top:103px;width:28px;height:12px'> 
[img width=28 height=12 src="民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif"/]
</span> 
<![endif]> 

<![if !vml]> 
[img width=28 height=12 src="民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif"/]
<![endif]>

------解决方案--------------------
C# code

string message = "<![if !vml]><span style='mso-ignore:vglayout;position:absolute;z-index:7;left:117px;top:103px;width:28px;height:12px'><img width=28 height=12 src=\"民生银行电子商户(B2C___)证书下载步骤2.files/image002.gif\" v:shapes=\"_x0000_s1032\"></span><![endif]>";
Regex reg = new Regex("<img border=\"0\" width=(\"?[0-9]*\"?) height=(\"?[0-9]*\"?) src=\"(.*?)\".*/?>");
message = reg.Replace(message, "[img width=$1 height=$2 src=\"$3\" /]");
Console.WriteLine(message);