@forensic-js/regex
Version:
A module that builds on the existing RegExp module, making it easier working with text matching and replacement both in the browser and node environments
27 lines (26 loc) • 1.81 kB
TypeScript
export declare type Pattern = string | RegExp;
export declare type Callback = (matches: string[], counts: number) => string;
/**
* iteratively replace every occurence of search patterns with the given replacements text in the
* given text
* @param patterns - search patterns, can be string or regex expressions,
* @param replacements - replacement text for each search pattern
* @param text - the text string to work on
* @param caseSensitive - specifies if search is case sensitive, this only applies to string
* patterns. for regex patterns, use RegExp ignoreCase flag (i)
* @param replaceCount - number of times to replace occurrences for each search pattern. by default
* all occurrences will be replaced. specify true or 1 to replace only first occurrence.
*/
export declare const replace: (patterns: string | RegExp | (string | RegExp)[], replacements: string | string[], text: string, caseSensitive?: boolean, replaceCount?: number | boolean) => string;
/**
* iteratively replace every occurence of search patterns with the return value of the
* given callback function in the given text
* @param patterns - search patterns, can be string or regex expressions,
* @param callback - the callback function
* @param text - the text string to work on
* @param caseSensitive - specifies if search is case sensitive, this only applies to string
* patterns. for regex patterns, use RegExp ignoreCase flag (i)
* @param replaceCount - number of times to replace occurrences for each search pattern. by default
* all occurrences will be replaced. specify true or 1 to replace only first occurrence.
*/
export declare const replaceCallback: (patterns: string | RegExp | (string | RegExp)[], callback: Callback, text: string, caseSensitive?: boolean, replaceCount?: number | boolean) => string;