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.


In reply to Re^3: Unescaped left brace in regex is passed through in regex by Anonymous Monk
in thread Unescaped left brace in regex is passed through in regex by gzh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.