ECMAScript proposal: RegExp escaping
15-Feb-2025 32
The ECMAScript proposal “RegExp escaping” (by Jordan Harband and Kevin Gibbons) specifies a function RegExp.escape() that, given a string text, creates an escaped version that matches text – if interpreted as a regular expression.
This proposal is currently at stage 3.
How does RegExp.escape() work?
What are the use cases for RegExp.escape()?
Example: replacing all occurrences of a text
Example: part of a regular expression must match a given text
Considerations for escaping
Escaping must work for all flags
Escaping must work in all syntactic contexts
Escaping must work whatever syntax precedes or succeeds the escaped text
Implementations of RegExp.escape()
Further reading.
ECMAScript proposal: RegExp escaping #js #javascript #ECMAScript #proposal: #RegExp #escaping https://javascript.ba/link/ecmascript-proposal-regexp-escaping