当前位置: 代码迷 >> ASP.NET >> 高难度正则匹配-高分猎头,该怎么解决
  详细解决方案

高难度正则匹配-高分猎头,该怎么解决

热度:4776   发布时间:2013-02-25 00:00:00.0
高难度正则匹配--高分猎头
<![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);
  相关解决方案