# SubMatches class
{: .no_toc }

Holds the strings that the capture groups of a pattern captured in one [**Match**](/tB/Packages/Contributed/tbRegExp/Match/index.md).

The [**SubMatches**](/tB/Packages/Contributed/tbRegExp/Match/SubMatches.md) property of a **Match** returns a **SubMatches** object. It holds one string for each capture group in the pattern, in the order of the groups. A pattern with no capture groups gives an object whose [**Count**](/tB/Packages/Contributed/tbRegExp/SubMatches/Count.md) is 0. A group that took no part in the match, such as one side of an alternation that did not match, still has its position, and its string is empty.

The strings are read by position or by name. The position is zero-based, as in the VBScript object model that the package replaces. A group written `(?<name>...)` has a name, and its string can be read by that name as well. [**Item**](/tB/Packages/Contributed/tbRegExp/SubMatches/Item.md) is the default member, so `sm(0)` is the same as `sm.Item(0)`. **For Each** goes through the strings in the order of their positions.

```tb check_build check_run
Dim re As New RegExp
re.Pattern = "(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})"

Dim matches As MatchCollection
Set matches = re.Execute("Released on 2026-10-11.")

Dim sm As SubMatches
Set sm = matches(0).SubMatches
Debug.Print sm.Count     ' 3
Debug.Print sm(0)        ' 2026
Debug.Print sm("month")  ' 10
```

The class has no member that adds or removes a string: the package fills a **SubMatches** from the groups of the match it belongs to.

## Properties

- [Count](/tB/Packages/Contributed/tbRegExp/SubMatches/Count.md) -- returns the number of strings
- [Item](/tB/Packages/Contributed/tbRegExp/SubMatches/Item.md) -- returns one string by position or by group name (the default member)

## Methods

- [NewEnum](/tB/Packages/Contributed/tbRegExp/SubMatches/NewEnum.md) -- returns the enumerator that **For Each** uses (hidden)

## See Also

- [Match](/tB/Packages/Contributed/tbRegExp/Match/index.md) class -- one match; its **SubMatches** property returns this object
- [MatchCollection](/tB/Packages/Contributed/tbRegExp/MatchCollection/index.md) class -- the matches of a search
- [RegExp](/tB/Packages/Contributed/tbRegExp/RegExp/index.md) class -- runs the search
- [For Each...Next](/tB/Core/For-Each-Next.md) statement -- goes through the strings
- [tbRegExp package](/tB/Packages/Contributed/tbRegExp/index.md) -- overview
