C# C正则表达式创建空格和短语上的字符串数组拆分(引号中)

C# C正则表达式创建空格和短语上的字符串数组拆分(引号中),c#,regex,C#,Regex,可能重复: 我正在处理各种字符串,这些字符串需要拆分成数组,只要有空格,除非引号中有空格 例如,我想说: this is "a simple" test …成为: [0] = this [1] = is [2] = "a simple" [3] = test 注意:我希望保留短语周围的引号,而不是删除它们。正则表达式: ".*?"|[^\s]+ 用法: String input = @"this is ""a simple"" test"; String[] matches =

可能重复:

我正在处理各种字符串,这些字符串需要拆分成数组,只要有空格,除非引号中有空格

例如,我想说:

this is "a simple" test
…成为:

[0] = this
[1] = is
[2] = "a simple"
[3] = test
注意:我希望保留短语周围的引号,而不是删除它们。

正则表达式:

".*?"|[^\s]+
用法:

String input = @"this is ""a simple"" test";
String[] matches =
    Regex.Matches(input, @""".*?""|[^\s]+").Cast<Match>().Select(m => m.Value).ToArray();

道歉!那些逗号不应该在那里,我现在已经把它们从问题中删除了。谢谢你强调这一点。