in reply to Re^2: Unescaped left brace in regex is passed through in regex
in thread Unescaped left brace in regex is passed through in regex
The left curly brace is a meta-character only in certain contexts. Outside those contexts, old versions of Perl would accept them as literals even if they were not escaped. I believe the intent is to eventually require a literal curly braces but not meta-character curly braces to be escaped.
In your first example. the left curly is a literal, and needs to be escaped. Looked at another way, the intent of the regex is to match something like "\x{deadbeef}".
In your second example, the curly braces are meta-characters specifying numbers of characters to match: two to four digits followed by a non-digit followed by two digits. So no escape required, and in fact escaping the left curly brackets would break the regex functionally, though it would still compile.
Maybe the error message is a bit unclear. It does not say "literal left curly," though that is probably implied by "is passed through ..."
[OT] the first regexp can probably be written /(\\x\{[[:xdigit:]]})/, provided that is really your intent. Note, though, that \d matches any digit, not just ASCII digits. That is to say, your regexp will match "123\N{U+096A}" (a.k.a. ASCII one, ASCII two, ASCII three, Devanagari digit four), whereas mine will not. If you need to match non-ASCII digits, stay with your own regexp.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Unescaped left brace in regex is passed through in regex
by Fletch (Bishop) on Jun 06, 2022 at 16:25 UTC |