# Test
{: .no_toc }

Returns whether the pattern finds a match in a string.

Syntax: *object*.**Test** ( *sourceString* ) **As Boolean**

*object*
: *required* An object expression that evaluates to a [**RegExp**](/tB/Packages/Contributed/tbRegExp/RegExp/index.md).

*sourceString*
: *required* A **String**, the text to search.

Returns **True** if [**Pattern**](/tB/Packages/Contributed/tbRegExp/RegExp/Pattern.md) finds a match in *sourceString*, otherwise **False**.

## Remarks

**Test** only reports whether a match exists. To read the matches, use [**Execute**](/tB/Packages/Contributed/tbRegExp/RegExp/Execute.md).

[**IgnoreCase**](/tB/Packages/Contributed/tbRegExp/RegExp/IgnoreCase.md), [**MultiLine**](/tB/Packages/Contributed/tbRegExp/RegExp/MultiLine.md) and [**DotAll**](/tB/Packages/Contributed/tbRegExp/RegExp/DotAll.md) apply to the matching. [**Global**](/tB/Packages/Contributed/tbRegExp/RegExp/Global.md) makes no difference, because one match is enough.

A search that backtracks without end, such as `(a+)+b` on thirty `a`, gives up instead of hanging, and **Test** then raises an error rather than returning a value: a search that ran out of steps did not establish whether the pattern matches, so there is no answer to return. See [**SearchStepLimit**](/tB/Packages/Contributed/tbRegExp/RegExp/SearchStepLimit.md).

When **Pattern** is not a valid regular expression, **Test** raises the compile error. Its number is [**LastErrorNumber**](/tB/Packages/Contributed/tbRegExp/RegExp/LastErrorNumber.md), its description is [**LastError**](/tB/Packages/Contributed/tbRegExp/RegExp/LastError.md), and its source is `RegExp`. Read [**IsValid**](/tB/Packages/Contributed/tbRegExp/RegExp/IsValid.md) first to avoid the error.

## Example

This example tests two strings against a pattern, then shows the effect of **IgnoreCase**.

```tb check_build check_run
Dim re As RegExp
Set re = New RegExp
re.Pattern = "\d{3}-\d{4}"
Debug.Print re.Test("Call 555-0142 today")  ' True
Debug.Print re.Test("Call us today")        ' False

re.Pattern = "^hello"
Debug.Print re.Test("Hello")                ' False
re.IgnoreCase = True
Debug.Print re.Test("Hello")                ' True
```

## See Also

- [Execute](/tB/Packages/Contributed/tbRegExp/RegExp/Execute.md) method -- returns the matches themselves
- [Replace](/tB/Packages/Contributed/tbRegExp/RegExp/Replace.md) method -- replaces the matches
- [Split](/tB/Packages/Contributed/tbRegExp/RegExp/Split.md) method -- splits a string at the matches
- [IsValid](/tB/Packages/Contributed/tbRegExp/RegExp/IsValid.md) property -- whether the pattern compiles
- [RegExp](/tB/Packages/Contributed/tbRegExp/RegExp/index.md) class -- overview
