使用Regex从电子邮件HTML中捕获内容

问题描述 投票:-1回答:1

所以我试图从电子邮件html中捕获一个特定的值。电子邮件的一部分是,

enter image description here

我想从电子邮件中捕获9/7/2018包含此日期的部分的HTML源代码为:

<table cellspacing=
=3D=220=22 cellpadding=3D=220=22 width=3D=22200=22 border=3D=220=22 align=
=3D=22left=22 class=3D=22left innertable=22 style=3D=22background:=23ffffff=
;border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;=22>
                                                            <tr>
                                                                <td width=
=3D=22200=22 align=3D=22left=22 valign=3D=22top=22 style=3D=22line-height:2=
2px; font-size:20px; font-family: Arial, sans-serif; color:=232a2a2a; text-=
decoration:none;=22>Date of Purchase:</td>
                                                            </tr>
                                                        </table>
                                   =20
                                                        <table cellspacing=
=3D=220=22 cellpadding=3D=220=22 width=3D=22288=22 border=3D=220=22 align=
=3D=22right=22 class=3D=22right innertable=22 style=3D=22background:=23ffff=
ff;border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;=22>
                                                            <tr>
                                                                <td width=
=3D=22200=22 align=3D=22right=22 valign=3D=22top=22 style=3D=22line-height:=
22px; font-size:20px; font-family: Arial, sans-serif; color:=23636363; text=
-decoration:none;=22>

**9/7/2018**

</td>
                                                            </tr>
                                                        </table>
                                                       =20
                                                    </td>
                                                    <td width=3D=2250=22 cl=
ass=3D=22gutter=22></td>
                                                </tr>
                                            </table>
                                            <table cellspacing=3D=220=22 ce=
llpadding=3D=220=22 width=3D=22600=22 border=3D=220=22 class=3D=22table=22 =
style=3D=22background:=23ffffff;border-collapse:collapse; mso-table-lspace:=
0pt; mso-table-rspace:0pt;=22>
                                                <tr>
                                                    <td width=3D=2250=22 cl=
ass=3D=22gutter=22></td>

我正在使用c#regex匹配可以使用多次(对于第一个表达式,我们可以找到包含DATE的整个标记,从第二个表达式我们可以从Tag找到日期)我尝试了一些表达式,但没有任何对我有效。

c# regex
1个回答
0
投票

首先,您必须将html解析为字符串。

现在您可以使用Regex找到您的日期:

MatchCollection dateFound = Regex.Matches(YOUR_STRING_NAME, "[0-9]*/[0-9]*/[0-9]{4}");
© www.soinside.com 2019 - 2024. All rights reserved.