Let's say I'm matching with a pattern that has subexpressions like this:
Regex myRegex = new Regex("(man|woman|couple) seeking (man|woman|couple|aardvark)");
string myStraightText = "Type is man seeking woman, age is 44";
MatchCollection myStraightMatches = myRegex.Matches(myStraightText);
string myGayText = "Type is man seeking man, age is 39";
MatchCollection myGayMatches = myRegex.Matches(myGayText);
string myBizarreText = "Type is couple seeking aardvark, age is N/A";
MatchCollection myBizarreMatches = myRegex.Matches(myBizarreText);
On the first match, I'd like to recover the information that the first subexpression matched "man" (and not "woman" or "couple") and the second subexpression matched "woman" (and not "man" or "couple" or "aardvark"). Whereas the second match it was "man" and "man" etc. Is this information available somewhere in the Match
object?
I only know how to get the complete matched string. For instance,
foreach (Match myMatch in myStraightMatches)
{
tbOutput.Text += String.Format("{0}\n", myMatch);
}
gets "man seeking woman". But I don't know which parts of that string came from which subexpression.