List<string>
文字列内のすべての文字列が必要です[ ]
:
Input = "[first] - [second] > [third] + 5"
だから私は最初、2番目、3番目が欲しいです。
あなたはこれを行うことができます
List<string> lst=Regex.Matches(input,@"(?<=\[).*?(?=\])")
.Cast<Match>()
.Select(x=>x.Value)
.ToList();
前の答えを拡張する:
static IEnumerable<string> GetListFromString(string stringToExtract)
{
var regex = new Regex(@"(?<=\[).*?(?=\])");
foreach (Match match in regex.Matches(stringToExtract))
{
yield return match.Value;
}
}