From 53d173f21603ec19d203095add7abf56baa69c8a Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Thu, 28 Nov 2024 21:37:37 -0500 Subject: [PATCH] Update files/en-us/web/javascript/reference/global_objects/regexp/escape/index.md Co-authored-by: Hamish Willee --- .../javascript/reference/global_objects/regexp/escape/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/javascript/reference/global_objects/regexp/escape/index.md b/files/en-us/web/javascript/reference/global_objects/regexp/escape/index.md index 5f6816e1eeaca64..7c8d21b3e6b086d 100644 --- a/files/en-us/web/javascript/reference/global_objects/regexp/escape/index.md +++ b/files/en-us/web/javascript/reference/global_objects/regexp/escape/index.md @@ -9,7 +9,7 @@ browser-compat: javascript.builtins.RegExp.escape The **`RegExp.escape()`** static method [escapes](/en-US/docs/Web/JavaScript/Reference/Regular_expressions#escape_sequences) any potential regex syntax characters in a string, and returns a new string that can be safely used as a [literal](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Literal_character) pattern for the {{jsxref("RegExp/RegExp", "RegExp()")}} constructor. -When dynamically creating a {{jsxref("RegExp")}} with user-provided content, always consider using this function to sanitize the input, unless the input is actually intended to contain regex syntax. In addition, don't try to re-implement its functionality by, for example, using {{jsxref("String.prototype.replaceAll()")}} to insert a `\` before all syntax characters, because `RegExp.escape()` can handle more edge cases and use the right escape sequence that doesn't cause syntax errors in certain contexts. +When dynamically creating a {{jsxref("RegExp")}} with user-provided content, consider using this function to sanitize the input (unless the input is actually intended to contain regex syntax). In addition, don't try to re-implement its functionality by, for example, using {{jsxref("String.prototype.replaceAll()")}} to insert a `\` before all syntax characters. `RegExp.escape()` is designed to use escape sequences that work in many more edge cases/contexts than hand-crafted code is likely to achieve. ## Syntax