From 80828ebc818c4d9a94f10c47fdaabe466ad7358a Mon Sep 17 00:00:00 2001 From: ljharb Date: Thu, 19 Oct 2023 18:16:00 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20tc39/pro?= =?UTF-8?q?posal-regex-escaping@03e29a5124c8fd53346d8bc0bc797e18ea0e8bff?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 3b50194..92d595c 100644 --- a/index.html +++ b/index.html @@ -2696,7 +2696,7 @@

Stage 2 Draft / October 12, 2023

RegExp.escape

+

Stage 2 Draft / October 19, 2023

RegExp.escape

22 Text Processing

@@ -2766,7 +2766,7 @@

22.2.5.2 RegExp.escape ( S )

"(){}[]|,.?*+-^$=<>\/#&!%:;@~'"`".

-
  1. Let str be ? ToString(S).
  2. Let cpList be a List containing in order the code points as defined in 6.1.4 of str, starting at the first element of str.
  3. Let toEscape be StringToCodePoints(the ASCII punctuators that need escaping).
  4. Let escapedList be a new empty List.
  5. For each code point c in cpList, do
    1. If escapedList is empty and c is matched by DecimalDigit, then
      1. Append code unit U+005C (REVERSE SOLIDUS) to escapedList.
      2. Append code unit U+0078 (LATIN SMALL LETTER X) to escapedList.
      3. Append code unit U+0033 (DIGIT THREE) to escapedList.
    2. Else if toEscape contains c or c is matched by WhiteSpace, then
      1. Append code unit U+005C (REVERSE SOLIDUS) to escapedList.
    3. Append the elements of UTF16EncodeCodePoint(c) to escapedList.
  6. Return CodePointsToString(escapedList).
+
  1. Let str be ? ToString(S).
  2. Let cpList be StringToCodePoints(str).
  3. Let toEscape be StringToCodePoints(the ASCII punctuators that need escaping).
  4. Let escapedList be a new empty List.
  5. For each code point c in cpList, do
    1. If escapedList is empty and c is matched by DecimalDigit, then
      1. Append code unit U+005C (REVERSE SOLIDUS) to escapedList.
      2. Append code unit U+0078 (LATIN SMALL LETTER X) to escapedList.
      3. Append code unit U+0033 (DIGIT THREE) to escapedList.
    2. Else if toEscape contains c or c is matched by WhiteSpace, then
      1. Append code unit U+005C (REVERSE SOLIDUS) to escapedList.
    3. Append the elements of UTF16EncodeCodePoint(c) to escapedList.
  6. Return CodePointsToString(escapedList).
Note

escape takes a string and escapes it so it can be literally represented as a pattern. In contrast EscapeRegExpPattern (as the name implies) takes a pattern and escapes it so that it can be represented as a string. While the two are related, they do not share the same character escape set or perform similar actions.