# Pattern
{: .no_toc }

Returns or sets the regular expression.

## Get

Returns a **String**.

Syntax: *object*.**Pattern**

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

The default value is an empty string.

## Let

Sets the regular expression.

Syntax: *object*.**Pattern** **=** *value*

*value*
: A **String** that holds the regular expression.

## Remarks

Setting a different pattern makes it compile again the next time it is needed. Setting the current pattern does nothing. A pattern that does not compile raises no error when it is set: [**IsValid**](/tB/Packages/Contributed/tbRegExp/RegExp/IsValid.md), [**LastError**](/tB/Packages/Contributed/tbRegExp/RegExp/LastError.md) and [**LastErrorNumber**](/tB/Packages/Contributed/tbRegExp/RegExp/LastErrorNumber.md) report the failure, and [**Execute**](/tB/Packages/Contributed/tbRegExp/RegExp/Execute.md), [**Test**](/tB/Packages/Contributed/tbRegExp/RegExp/Test.md), [**Replace**](/tB/Packages/Contributed/tbRegExp/RegExp/Replace.md) and [**Split**](/tB/Packages/Contributed/tbRegExp/RegExp/Split.md) raise it.

A named group is written `(?<name>...)`. Its text is read from the [**SubMatches**](/tB/Packages/Contributed/tbRegExp/SubMatches/index.md) of a [**Match**](/tB/Packages/Contributed/tbRegExp/Match/index.md) by name, and used in [**Replace**](/tB/Packages/Contributed/tbRegExp/RegExp/Replace.md) as `$<name>`. A name starts with a letter or an underscore and goes on with letters, digits and underscores. [**Pattern syntax**](/tB/Packages/Contributed/tbRegExp/PatternSyntax.md) covers the rest of the pattern syntax.

## Example

```tb check_build check_run
Dim re As RegExp
Set re = New RegExp
Debug.Print re.Pattern = vbNullString  ' True

re.Pattern = "b+"
Debug.Print re.Pattern                 ' b+
Debug.Print re.Replace("abbbc", "-")   ' a-c
```

## See Also

- [IsValid](/tB/Packages/Contributed/tbRegExp/RegExp/IsValid.md) property -- whether the pattern compiles
- [IgnoreCase](/tB/Packages/Contributed/tbRegExp/RegExp/IgnoreCase.md) property -- the option that changes how the pattern is compiled
- [Execute](/tB/Packages/Contributed/tbRegExp/RegExp/Execute.md) method -- returns the matches
- [RegExp](/tB/Packages/Contributed/tbRegExp/RegExp/index.md) class -- overview
