apps-script-utils 2.1.1 Help

escapeRegExp

function escapeRegExp(value: string): string;

Put user input through this before building a RegExp from it, and a dot stays a dot instead of matching any character.

Parameters

Parameter

Type

Description

value

string

The string to escape. It must not be empty.

Returns

string — the escaped string, safe to drop into a pattern.

Throws

Exception

Condition

EmptyStringException

the value is not a string, or is empty.

Examples

Escaping

escapeRegExp("a.b*c"); // => "a\\.b\\*c" new RegExp(escapeRegExp("1.5")).test("1x5"); // => false

See also

Source

src/lang/string/escapeRegExp.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.