1

给定以下字符串:

string = @"
/SQL "\Geneva\GenevaAfterTaxExtracts" /SERVER SMAMSQL2602A /CHECKPOINTING OFF 
/SET "\Package.Variables[User::Portfolio].Properties[Value]";"2504,2505,2506,2507,336,339,340,343,344,345,346,348,349,350" 
/SET "\Package.Variables[User::FirstMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::LastMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::Files].Properties[Value]";"Valuations" /REPORTING E"

我想匹配和 nextMatch 如下:

/SET "\Package.Variables[User::Portfolio].Properties[Value]";"2504,2505,2506,2507,336,339,340,343,344,345,346,348,349,350" 
/SET "\Package.Variables[User::FirstMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::LastMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::Files].Properties[Value]";"Valuations"

我正在使用以下内容:

Regex re = new Regex(@"\/SET ([^\/]+)");
Match match = re.Match(command);

第一个和最后一个工作正常,但日期在“/”之前被截断,如下所示

/SET "\Package.Variables[User::FirstMonthEnd].Properties[Value]";"8

/SET "\Package.Variables[User::LastMonthEnd].Properties[Value]";"8

如何更改 Regex(@"/SET ([^/]+)") 使其在日期上也匹配?

提前致谢。

4

2 回答 2

2

如果它们是单独的行

/SET.*

如果他们在同一行

/SET.*?(?=/[a-zA-Z]+|$)

List<String> output=Regex.Matches(input,regex)
                         .Cast<Match>()
                         .Select(x=>x.Value)
                         .ToList();
于 2013-10-01T18:29:19.000 回答
0

这个正则表达式怎么样:

Regex re = new Regex(@"\/SET (.+?)(?=( *\/[a-z]| *$))");
于 2013-10-01T18:50:09.013 回答