# NewEnum
{: .no_toc }

Returns the enumerator that **For Each** uses to go through the strings of the collection.

Syntax: *object*.**NewEnum** **As IUnknown**

*object*
: *required* An object expression that evaluates to a **SubMatches**.

Returns an **IUnknown** that refers to a new enumerator over the strings of the capture groups, which starts at the first one.

## Remarks

**NewEnum** is declared with the [**Enumerator**](/tB/Core/Attributes.md#enumerator) attribute, which makes it the member that [**For Each**](/tB/Core/For-Each-Next.md) calls to start an enumeration. [Custom Enumerators](/Features/Language/Custom-Enumerators.md) describes the rule. It is also declared [**Hidden**](/tB/Core/Attributes.md#hidden), so it does not appear in certain IntelliSense lists.

The elements come in the order of their positions, from 0 to [**Count**](/tB/Packages/Contributed/tbRegExp/SubMatches/Count.md) - 1, and each is the string of one group. A group that took no part in the match gives an empty string. A **Variant** variable receives each element, as in the example.

A program does not need to call **NewEnum**. **For Each** does it.

## Example

```tb check_build check_run
Dim re As New RegExp
re.Pattern = "(\w+)@(\w+)\.com"

Dim matches As MatchCollection
Set matches = re.Execute("ann@example.com")

Dim sm As SubMatches
Set sm = matches(0).SubMatches

Dim part As Variant
For Each part In sm
    Debug.Print part
Next
' Output:
' ann
' example
```

## See Also

- [Item](/tB/Packages/Contributed/tbRegExp/SubMatches/Item.md) property -- returns a string by position or by name
- [Count](/tB/Packages/Contributed/tbRegExp/SubMatches/Count.md) property -- the number of strings
- [For Each...Next](/tB/Core/For-Each-Next.md) statement -- uses the enumerator
- [SubMatches](/tB/Packages/Contributed/tbRegExp/SubMatches/index.md) class -- overview
