Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: No need to escape right brace in regex

by Athanasius (Bishop)
on Oct 21, 2014 at 04:40 UTC ( #1104519=note: print w/replies, xml ) Need Help??


in reply to No need to escape right brace in regex

I don’t know why, but this behaviour is apparently by design:

A literal "{" should now be escaped in a pattern

If you want a literal left curly bracket (also called a left brace) in a regular expression pattern, you should now escape it by either preceding it with a backslash ("\{") or enclosing it within square brackets "[{]", or by using \Q; otherwise a deprecation warning will be raised. This was first announced as forthcoming in the v5.16 release; it will allow future extensions to the language to happen.

perl5211delta#Deprecations

Presumably the planned “future extensions to the language” (whatever they are) won’t be affected by unescaped right braces.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: No need to escape right brace in regex
by no_slogan (Deacon) on Oct 21, 2014 at 06:57 UTC

    { is only special if it's followed by /\d+,?\d*}/. If they want to add anything else that can go between { }, they have to either add a simple rule to the language (always backslash { unless you want special behavior), or a bunch of weird rules that they might want to change again later.

    } is never special unless a preceding { makes it so.

      But you don't *always* get the deprecation warning:
      C:\>perl -le "$_ =~ /{}/;" C:\>perl -le "$_ =~ /.+{}/;" C:\>perl -le "$_ =~ /a+{}/;" C:\>perl -le "$_ =~ /(a+)?{}/;" C:\>perl -le "$_ =~ /a{}/;" Unescaped left brace in regex is deprecated, passed through in regex; +marked by <-- HERE in m/a{ <-- HERE }/ at -e line 1. C:\>perl -le "$_ =~ /\d{}/;" Unescaped left brace in regex is deprecated, passed through in regex; +marked by <-- HERE in m/\d{ <-- HERE }/ at -e line 1. C:\>
      That behaviour fits ok with the (undetailed) documentation that Athanasius found, but does it tie in at all with the cases you're describing ?
      (I don't see the connection, though that doesn't mean there isn't one :-)

      Cheers,
      Rob
        This is really a bit strange.

        Looks like they are only simplifying parsing of quantifiers like in /a{1,2}/ to avoid look ahead analysis.

        All other cases you've shown can not be quantifiers.

        Maybe the warning should be better phrased?

        Cheers Rolf

        (addicted to the Perl Programming Language and ☆☆☆☆ :)

      Hmm I think it's even more complicated, there is still (?{code}) and (??{code}) to handle.

      But yes looks like they are cleaning up some messi parsing rules.

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

        But yes looks like they are cleaning up some messi parsing rules

        It does look that way - I guess all will become clear eventually.
        In the meantime I'll just escape both '{' and '}'.

        The same warning showed up with the advent of 5.18 (or was it 5.20) and I eradicated those warnings (by escaping the braces) accordingly.
        But 5.21.x has uncovered other situations where braces are unacceptably unescaped - situations that 5.20 and earlier didn't care about.

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1104519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2019-08-23 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?