deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

`@std/regexp/escape` vs `RegExp.escape` (newly Stage 3!)

Open lionel-rowe opened this issue 1 year ago • 3 comments

Mainly a tracking issue, probably (?) no action needed for now.

The RegExp.escape proposal has overcome its TC39 deadlock and is now at Stage 3!

The exact details of the implementation in the spec differ somewhat from @std/regexp/escape, but as far as I can tell, the only functional difference is that alphanumeric chars get automatically escaped at the start of the string, such that RegExp.escape('7_8_9') becomes '\\x37_8_9', which sacrifices a certain amount of readability in exchange for allowing safe interpolation immediately after the sequences \0, \<digits>, and \c.

Not sure if desirable or worthwhile to replace at this stage, but I've created a lightweight polyfill that passes the test262 tests and could work as a drop-in replacement for @std/regexp/escape. But probably better to just wait until implementations drop and then deprecate @std/regexp/escape.

lionel-rowe avatar Aug 23 '24 06:08 lionel-rowe

But probably better to just wait until implementations drop and then deprecate @std/regexp/escape.

I like this option 🙂

iuioiua avatar Aug 25 '24 03:08 iuioiua

Now stage 4 https://github.com/tc39/proposal-regex-escaping/issues/58#issuecomment-2666734135

balupton avatar Feb 19 '25 01:02 balupton

Let's add the deprecation notice when it's shipped to Deno (and maybe Chrome).

Note: According to MDN, Safari and Firefox already implement it. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/escape

kt3k avatar Feb 19 '25 04:02 kt3k