Skip to main content
default.match - node__assert.d.ts - Node documentation
function default.match

Usage in Deno

```typescript import mod from "node:node__assert.d.ts"; ```
match(
value: string,
regExp: RegExp,
message?: string | Error,
): void
Expects the `string` input to match the regular expression. ```js import assert from 'node:assert/strict'; assert.match('I will fail', /pass/); // AssertionError [ERR_ASSERTION]: The input did not match the regular ... assert.match(123, /pass/); // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string. assert.match('I will pass', /pass/); // OK ``` If the values do not match, or if the `string` argument is of another type than `string`, an `[AssertionError](../.././node__assert.d.ts/~/default.AssertionError)` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of an [Error](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-error) then it will be thrown instead of the `[AssertionError](../.././node__assert.d.ts/~/default.AssertionError)`.

Parameters

value: string
regExp: RegExp
optional
message: string | Error

Return Type

void