Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用正则表达式匹配某些字符串_C#_Regex - Fatal编程技术网

C# 如何使用正则表达式匹配某些字符串

C# 如何使用正则表达式匹配某些字符串,c#,regex,C#,Regex,给定以下字符串: 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[U

给定以下字符串:

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"
我希望匹配和下一次匹配如下:

/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::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([^/]+)),使其与日期匹配


提前感谢。

如果它们是单独的行

/SET.*
如果他们在同一条线上

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

List output=Regex.Matches(输入,Regex)
.Cast()
.选择(x=>x.Value)
.ToList();
这个正则表达式怎么样:

Regex re = new Regex(@"\/SET (.+?)(?=( *\/[a-z]| *$))");

请用您正在使用的语言标记您的问题。非常感谢!在同一条线上工作。我被困了几个小时!:)Anirudh的解决方案/集合。*?(?=/[a-zA-Z]+|$)对我来说很好。感谢您的快速重播!