0

I've looked at answers to similar questions and they didn't help me- I'm confused about how captures should work. Here's my code:

var searchMe = "### applez ### airplanez #### apez";
var m = Regex.Match(searchMe, @"(a.+?z)");

Debug.WriteLine($"Found {m.Groups.Count} groups");
Debug.WriteLine($"and {m.Captures.Count} captures");
Debug.WriteLine($"and {m.Groups[1].Captures.Count} group[1] captures");

output:

Found 2 groups
and 1 captures
and 1 group[1] captures

When I try the same text and regex on http://regexstorm.net/tester, I get 3 matches. Why am I seeing only 1 match and 1 capture in my code?

EDIT: The reason is that I was using Regex.Match instead of Regex.Matches.

Eric Jorgensen
  • 1,682
  • 2
  • 14
  • 23

0 Answers0