-5

我有一个字符串

PrintFileURL("13572_BranchInformationReport_2012-06-29.zip","13572_BranchInformationReport_2012-06-29.zip",0,"184277","Jun 29 1:30","/icons/default.gif")

PrintFileURL("13572_IndividualInformationReportDelta_2012-06-29_033352.zip","13572_IndividualInformationReportDelta_2012-06-29_033352.zip",0,"53147","Jun 29 3:33","/icons/default.gif")

如果我想 使用 c# 从上述字符串中提取13572_IndividualInformationReportDelta_2012-06-29_033352.zip和提取,那么正则表达式可能是什么...?13572_BranchInformationReport_2012-06-29.zip

4

2 回答 2

1

这个应该完全适用于前两个文件,但如果文件名中有任何额外的特殊字符,则不会工作:

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            const string example = "PrintFileURL(\"13572_IndividualInformationReportDelta_2012-06-29_033352.zip\",\"13572_IndividualInformationReportDelta_2012-06-29_033352.zip\",0,\"53147\",\"Jun 29 3:33\",\"/icons/default.gif\")";
            Console.WriteLine(example);

            const string pattern = "\\\"([a-zA-Z0-9\\-_]*?\\..*?)\\\"";
            var regex = new Regex(pattern);
            var result = regex.Matches(example);
            foreach (Match item in result)
            {
                Console.WriteLine(item.Groups[1]);
            }
        }
    }
}
于 2012-06-29T10:59:29.527 回答
0

你可以试试这个:

正则表达式

进而

var regex = new Regex("@(?<=\")(.*?)(?=\")");

var result = regex.Matches(example);
foreach (Match item in result)
{
    Console.WriteLine(item.Groups[1]);
}
于 2012-06-29T11:24:25.160 回答