Regex. Escape Synchronous
Make user-provided text safe to place inside a regular expression as a literal. Punctuation such as dots and brackets will match itself instead of gaining regex meaning.
Luau
Regex.Escape(text: string) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
text | string | The literal text to match. |
Returns
stringA regex fragment that matches precisely that text.
Usage notes
Escape only the literal piece; you can still add your own anchors or pattern syntax around it.
Example
Luau
local filename = "settings.json"
local exact = Regex.new("^" .. Regex.Escape(filename) .. "$")
print(exact:Match("settings.json")) -- settings.json
print(exact:Match("settingsXjson")) -- nil