Skip to content

replaceRegExpMatches

Replace every match of a global regular expression with what a replacer builds from the match. The typed counterpart of String.prototype.replaceAll with a callback, whose arguments are typed only positionally.

Import:

import { replaceRegExpMatches } from '@mnaoumov/typescript-dev-toolkit/docs-site/api-doc-text-utils';

Signature:

function replaceRegExpMatches(text: string, regExp: RegExp, replacer: (match: RegExpMatchArray) => string): string

Parameters:

Parameter Type Description
text string The text.
regExp RegExp The regular expression; it must carry the g flag.
replacer (match: RegExpMatchArray) => string Builds the replacement of one match.

Returns: string — The text with every match replaced.