0

我有一个包含这些行的 HTML 文件 -

<script>PrintFileURL("13572_BranchInformationReport_2012-06-29.xml","13572_BranchInformationReport_2012-06-29.zip",0,"184277","Jun 29  1:30","/icons/default.gif")</script>
<script>PrintFileURL("13572_BranchInformationReport_2012-07-02.zip","13572_BranchInformationReport_2012-07-02.zip",0,"184302","Jul  2  1:30","/icons/default.gif")</script>
<script>PrintFileURL("13572_IndividualInformationReportDelta_2012-06-29_033352.zip","13572_IndividualInformationReportDelta_2012-06-29_033352.zip",0,"53147","Jun 29  3:33","/icons/default.gif")</script>
<script>PrintFileURL("13572_IndividualInformationReportDelta_2012-07-02_033458.zip","13572_IndividualInformationReportDelta_2012-07-02_033458.zip",0,"62719","Jul  2  3:35","/icons/default.gif")</script>
<script>PrintFileURL("13572_IndividualInformationReport_2012-07-01.acc","13572_IndividualInformationReport_2012-07-01.zip",0,"4033364","Jul  1 12:50","/icons/default.gif")</script>

我需要从这个字符串中提取文件名 -

13572_IndividualInformationReportDelta_2012-06-29_033352.zip

13572_IndividualInformationReportDelta_2012-07-02_033458.zip

13572_BranchInformationReport_2012-07-02.zip

13572_BranchInformationReport_2012-07-02.xml

13572_IndividualInformationReport_2012-07-01.acc

现在我正在使用以下正则表达式代码 -

 var fileNames = from Match m in Regex.Matches(pageSource, @"[0-9]+_+[A-Za-z]+_+[0-9]+-+[0-9]+-+[0-9]+\.+(acc|zip|app|xml|def|enr|exm|fpr|pnd|trm)")
                        select m.Value;

它给了我最后 3 个文件,但没有给我前 2 个文件。

有人可以为我提供一个正则表达式来提取所有这些文件吗?

提前致谢 :)

4

3 回答 3

1

添加(_+[0-9]+)?到它:

var fileNames = from Match m in Regex.Matches(pageSource, @"[0-9]+_+[A-Za-z]+_+[0-9]+-+[0-9]+-+[0-9]+(_+[0-9]+)?\.+(acc|zip|app|xml|def|enr|exm|fpr|pnd|trm)")

这意味着它还应该与_+[0-9]+文件名中的可选后缀匹配行。

于 2012-07-02T08:36:05.837 回答
0

\d+_\w+_\d+-\d+-\d+(_\d+)?\.+(acc|zip|app|xml|def|enr|exm|fpr|pnd|trm)

于 2012-07-02T08:42:04.897 回答
0

试试下面的正则表达式

@"^[^\(]*\(\""([^""]+)\"""

并使用:

match.Groups[1];
于 2012-07-02T08:44:00.147 回答