develooper Front page | perl.perl5.porters | Postings from May 2019

[perl #134141] Further elimination of unescaped left braces inregular expressions

James E Keenan
May 25, 2019 02:19
[perl #134141] Further elimination of unescaped left braces inregular expressions
Message ID:
# New Ticket Created by  James E Keenan 
# Please include the string:  [perl #134141]
# in the subject line of all future correspondence about this issue. 
# <URL: >

pod/perldeprecation.pod contains the following entry for perl-5.32:

Unescaped left braces in regular expressions

The simple rule to remember, if you want to match a literal
"{" character (U+007B "LEFT CURLY BRACKET") in a regular
expression pattern, is to escape each literal instance of
it in some way. Generally easiest is to precede it with a
backslash, like "\{" or enclose it in square brackets
("[{]"). If the pattern delimiters are also braces, any
matching right brace ("}") should also be escaped to avoid
confusing the parser, for example,


Forcing literal "{" characters to be escaped will enable
the Perl language to be extended in various ways in future
releases. To avoid needlessly breaking existing code, the
restriction is is not enforced in contexts where there are
unlikely to ever be extensions that could conflict with the
use there of "{" as a literal. A non-deprecation warning
that the left brace is being taken literally is raised in
contexts where there could be confusion about it.

Literal uses of "{" were deprecated in Perl 5.20, and some
uses of it started to give deprecation warnings since.
These cases were made fatal in Perl 5.26. Due to an
oversight, not all cases of a use of a literal "{" got a
deprecation warning. Some cases started warning in Perl
5.26, and were made fatal in Perl 5.30. Other cases started
in Perl 5.28, and will be made fatal in 5.32.

This entry was recorded in the following commit:

commit 0367231ce260cd08bcb13082d510e5778668bcc1
Author: Karl Williamson <>
Date: Thu Jan 4 12:53:29 2018 -0700

Raise deprecation for qr/(?foo})/

An unescaped left brace that is meant to be taken literally
is officially deprecated, though there are no plans to
remove it in contexts where we don't expect to use it to
mean something else, and no warning is raised in those

reg_mesg.t tests the known set of these contexts, currently
(after this commit):

/^{/ /foo|{/ /foo|^{/ /foo(:?{bar)/ /\s*{/ /a{3,4}{/

This commit deprecates this context: /foo({bar})/

This probably should have been illegal all along when 'bar'
is a valid quantifier, as we do with the other quantifiers
that follow a left paren whose illegality we haven't
already taken advantage of to mean something else:

qr/(+0)/ Quantifier follows nothing in regex

This deprecation will allow ({...}) to be usable for a
possible future regex extension

Make it so. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About