我想用这个.Net正则表达式.Spl它方法将此输入字符串拆分为array.It must spl它 on wh它espace unless 它 是 enclosed in a quote.
Input: 这里 是 "我的线" 它 有 "six matches"
预期输出:
- 这里
- 是
- 我的线
- 它
- 有
- six matches
我需要什么图案?我还需要指定任何RegexOptions吗?
我想用这个.Net正则表达式.Spl它方法将此输入字符串拆分为array.It must spl它 on wh它espace unless 它 是 enclosed in a quote.
Input: 这里 是 "我的线" 它 有 "six matches"
预期输出:
我需要什么图案?我还需要指定任何RegexOptions吗?
不需要 Select
正则表达式:
\w+|"[\w\s]*"
C#:
Regex regex = new Regex(@"\w+|""[\w\s]*""");
Or if you need to exclude " characters:
Regex
.Matches(input, @"(?<match>\w+)|\""(?<match>[\w\s]*)""")
.Cast<Match>()
.Select(m => m.Groups["match"].Value)
.ToList()
.ForEach(s => Console.WriteLine(s));