denoland / denoland/std

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

Open
#5,794 3 comments 0 reactions 0 assignees View on GitHub
regexp suggestion
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

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

The [`RegExp.escape`](https://github.com/tc39/proposal-regex-escaping) proposal has overcome its TC39 deadlock and is now at Stage 3!

The exact details of the implementation in [the spec](http://tc39.es/proposal-regex-escaping/) 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`, `\`, and `\c`.

Not sure if desirable or worthwhile to replace at this stage, but I've created a [lightweight polyfill](https://github.com/lionel-rowe/regexp-escape-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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.