像这样的东西?
StringCollection resultList = new StringCollection();
try
{
Regex regexObj = new Regex("\"([^\"]+)\"");
Match matchResult = regexObj.Match(subjectString);
while (matchResult.Success)
{
resultList.Add(matchResult.Groups[1].Value);
matchResult = matchResult.NextMatch();
}
}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}
Run Code Online (Sandbox Code Playgroud)
如果subjectString是"你好""为什么""WWWWWEEEEEE",那应该给你一个包含以下内容的清单:
一个更紧凑的例子,它使用静态Regex类,只是将匹配写入控制台而不是添加到集合:
var subject = "\"Hello\" \"WHY ARE\" \"WWWWWEEEEEE\"";
var match = Regex.Match(subject, "\"([^\"]+)\"");
while (match.Success)
{
Console.WriteLine(match.Groups[1].Value);
match = match.NextMatch();
}
Run Code Online (Sandbox Code Playgroud)