次のような文字列を解析する必要があります。
"some text {{text in double brackets}}{{another text}}..."
正規表現を使用して、二重括弧からテキストを C# の文字列配列として抽出するにはどうすればよいですか?
string input = @"some text {{text in double brackets}}{{another text}}...";
var matches = Regex.Matches(input, @"\{\{(.+?)\}\}")
.Cast<Match>()
.Select(m => m.Groups[1].Value)
.ToList();
この文字列を使用
@"\{\{([^}]*)\}\}"
あなたの正規表現のために
var inputText = "some text {{text in double brackets}}{{another text}}...";
Regex re = new Regex(@"\{\{([^}]*)\}\}");
foreach (Match m in re.Matches(inputText))
{
Console.WriteLine(m.Value);
}
括弧内から実際のテキストを取得するには、名前付きグループを使用します
var r = new Regex(@"{{(?<inner>.*?)}}", RegexOptions.Multiline);
foreach(Match m in r.Matches("some text {{text in double brackets}}{{another text}}..."))
{
Console.WriteLine(m.Groups["inner"].Value);
}