Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

How is escaping of plain text affected by this proposal? #71

Closed
rauschma opened this issue Oct 19, 2022 · 3 comments
Closed

How is escaping of plain text affected by this proposal? #71

rauschma opened this issue Oct 19, 2022 · 3 comments

Comments

@rauschma
Copy link

I’m currently using this function to escape plain text – which will have to change(?)

export function escapeForRegExp(str: string) {
  return str.replace(/[\\^$.*+?()\[\]{}|=!<>:\-]/g, '\\$&');
}

It may make sense to show an implementation of such a function in this proposal or to link to one elsewhere.

@mathiasbynens
Copy link
Member

mathiasbynens commented Oct 21, 2022

The list of characters in the second bullet point of https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag that are not in https://github.com/tc39/proposal-regex-escaping/blob/d2ff7fe02009f728eb3c2e749e354c72427abd08/EscapedChars.md#syntaxcharacter-proposal is:

/
-
&
!
#
%
,
:
;
<
=
>
@
`
~

If the RegExp escaping proposal wants to support using its output within a character class in v mode, these would need to be added. However, u mode currently disallows unnecessary escapes, e.g. /</u is fine but /\</u is an early syntax error — so the escaping proposal cannot satisfy both u and v at the same time. This is something for the escaping proposal champions to look into.

@rauschma
Copy link
Author

rauschma commented Oct 21, 2022

Hmm. Seems problematic. Is changing /u to allow unnecessary escapes an option?

Edit – yes that is an option: #27

@ljharb
Copy link
Member

ljharb commented Oct 21, 2022

That sounds to me like a cross-cutting concern that this proposal needs to account for before advancing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants