给出以下字符串:
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
如何更改正则表达式(@" / SET([^ /] +)")以及它在日期上匹配的方式?
提前致谢。
答案 0 :(得分:2)
如果它们是单独的行
/SET.*
如果他们在同一条线上
/SET.*?(?=/[a-zA-Z]+|$)
List<String> output=Regex.Matches(input,regex)
.Cast<Match>()
.Select(x=>x.Value)
.ToList();
答案 1 :(得分:0)
这个正则表达式怎么样:
Regex re = new Regex(@"\/SET (.+?)(?=( *\/[a-z]| *$))");