That’s because Groups are a special property of the Match class; they only work if you use special “capturing groups” in your pattern. For example, suppose we want to test the input
with the pattern
using the Matches activity. This will give you a list of Match objects (
IEnumerable<Match>), let’s call it
matches, with one element. Let’s call this first match
match = matches.First. You may also have to add
System.Text.RegularExpressions to your imported namespaces for everything to work and autocomplete properly.
Now, the whole pattern matches the substring
defghi123, which is stored in
match.Value, but it also contains two unnamed groups and one named group “foo”. The unnamed groups are indexed from 1, so you will find that
ghi. The second of these, at the end of the pattern, is optional and was not present in the input; you can test for this with the property
match.Groups(2).Success (False in this case). Named groups behave just the same but are accessed by string identifiers:
For those wanting to know all the details (there are many, many more) about regular expressions in .NET, I suggest you start here.