[英]How to match certain strings using regex regular expression
给定以下字符串:
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([^ /] +)”),使其也与日期匹配?
提前致谢。
如果它们是单独的行
/SET.*
如果他们在同一行
/SET.*?(?=/[a-zA-Z]+|$)
List<String> output=Regex.Matches(input,regex)
.Cast<Match>()
.Select(x=>x.Value)
.ToList();
这个正则表达式如何:
Regex re = new Regex(@"\/SET (.+?)(?=( *\/[a-z]| *$))");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.