假设我有一个这样的多行字符串:
STARTFRUIT
banana
ENDFRUIT
STARTFRUIT
avocado
ENDFRUIT
STARTVEGGIE
rhubarb
ENDVEGGIE
STARTFRUIT
lime
ENDFRUIT
Run Code Online (Sandbox Code Playgroud)
我想搜寻所有水果,没有蔬菜.我试试这个:
MatchCollection myMatches = Regex.Matches(tbBlob.Text, "STARTFRUIT.*ENDFRUIT", RegexOptions.Singleline);
foreach (var myMatch in myMatches)
{
Forms.MessageBox.Show(String.Format("Match: {0}", myMatch), "Match", Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Information);
}
Run Code Online (Sandbox Code Playgroud)
问题是,它给了我一个包含第一个STARTFRUIT和开头以及最后一个ENDFRUIT的大匹配,而不是给我一个三个匹配的数组.有没有办法"最小化"匹配搜索?我没有看到任何帮助RegexOptions.