私にとっては、これに Regex を使用しない方がすっきりしているように感じます。要件を少し緩めて正規表現のみを試すと、終了引用符と開始引用符の間のテキストが一致します。
おそらく、手動で行うとより良い結果が得られるでしょうか?
string[] extractBetweenQuotes(string str)
{
var list = new List<string>();
int firstQuote = 0;
firstQuote = str.IndexOf("\"");
while (firstQuote > -1)
{
int secondQuote = str.IndexOf("\"", firstQuote + 1);
if (secondQuote > -1)
{
list.Add(str.Substring(firstQuote + 1, secondQuote - (firstQuote + 1)));
firstQuote = str.IndexOf("\"", secondQuote + 1);
continue;
}
firstQuote = str.IndexOf("\"", firstQuote + 1);
}
return list.ToArray();
}
使用法:
string str = "there is a child object with name \"Child 1\" under parent \"Parent 1\" in the tree";
string[] parts = extractBetweenQuotes(str); // Child 1 and Parent 1 (no quotes)