Writing code

FUNCTION

escapeRegExpText

@skmtc/lang-typescript 0.19.1

A pattern that matches exactly text: each syntax character is escaped (a.b → a\.b), and each line terminator becomes its escape. Only characters that may be escaped under the u and v flags are escaped, so the result is valid with any flags.

Signature

import { escapeRegExpText } from '@skmtc/lang-typescript'

escapeRegExpText(text: string): string

Parameters

text, string required
Example
escapeRegExpText('a.b')     // 'a\\.b'
escapeRegExpText('count()') // 'count\\(\\)'
escapeRegExpText('id')      // 'id'

Returns

string