Skip to content
Regular expressionsReference

Regex.Escape

Escape text for a literal match in a regex pattern.

Details#

Escape text for a literal match in a regex pattern. String with regex metacharacters escaped using a backslash.

Signature#

Luau
Regex.Escape(text: string): string

Parameters#

ParameterTypeDescription
textstringLiteral text to include in a regex.

Returns#

String with regex metacharacters escaped using a backslash.

Examples#

Local example

Luau
local pattern = Regex.new(Regex.Escape("notes.txt"))
print(pattern:Match("open notes.txt")) -- notes.txt