From 217fe5c602319be4aabdc59dd5c38cb868e9119c Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 7 Sep 2023 19:43:31 -0400 Subject: [PATCH] Update docs --- docs/regular-expressions.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/regular-expressions.md b/docs/regular-expressions.md index ee9564a3f94..de1e99d2861 100644 --- a/docs/regular-expressions.md +++ b/docs/regular-expressions.md @@ -10,11 +10,13 @@ Regular expressions are a powerful tool. However, they are also very expensive i 4. Underscore (`_`) 5. Everything else (except dash, `-`) in ASCII order: `\t\n\r !"#$%&()*+,./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^abcdefghijklmnopqrstuvwxyz{|}~` 6. _Last_, dash (`-`) - 7. Example 1, both equivalent, Wrong order: `[_a-zA-Z0-9-,.]`, Correct: `[0-9A-Za-z_,.-]` - 8. Example 2, both equivalent, Wrong order: `[;a-z0-9]`, Correct: `[0-9a-z;]` + - Example 1, both equivalent, Wrong order: `[_a-zA-Z0-9-,.]`, Correct: `[0-9A-Za-z_,.-]` + - Example 2, both equivalent, Wrong order: `[;a-z0-9]`, Correct: `[0-9a-z;]` * **Inside character classes, avoid unnecessary character escaping.** Go does not complain about extra character escaping but avoid it to improve cache performance. Inside a character class, _most_ characters do not need to be escaped, as Go assumes you mean the literal character. * These characters which normally have special meaning in regular expressions, _inside character classes_ do **not** need to be escaped: `$`, `(`, `)`, `*`, `+`, `.`, `?`, `^`, `{`, `|`, `}`. * Dash (`-`), when it is last in the character class or otherwise unambiguously not part of a range, does not need to be escaped. If in doubt, place the dash _last_ in the character class (_e.g._, `[a-c-]`) or escape the dash (_e.g._, `\-`). * Angle brackets (`[`, `]`) always need to be escaped in a character class. * Example 1, both equivalent, Unnecessary escapes: `[\$\(\.\?\|]`, Correct: `[$(.?|]` * Example 2, both equivalent, Unnecessary escapes, wrong order: `[a-z\-0-9_A-Z\.]`, Correct: `[0-9A-Za-z_.-]` + +