Unescaped left brace regex error
Asked Answered
V

2

14

I’m not an expert in regex and can't figure what I am supposed to change here.

I get these two errors

Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^(.*?)(\\)?\${ <-- HERE ([^{}]+)}(.*)$/ at /usr/share/perl5/Debconf/Question.pm line 72.

Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^}]+)}/ at /usr/share/perl5/Debconf/Config.pm line 30.

When I jump to the line 72 this is what I see

while ($rest =~ m/^(.*?)(\\)?\${([^{}]+)}(.*)$/sg) {
Viewer answered 2/4, 2017 at 7:11 Comment(3)
Let me just guess because you are missing any useful context: you are using a newer Perl version on your system then the one which came with the system and now you are seeing problems caused by this. For now these are just warnings you can ignore if you don't understand Perl. In any case better use the original Perl which came with your system for any scripts which are shipped with the system. If you understand Perl you can fix the warning by escaping the { inside the Regex, i.e. \{.Brassiere
Thanks a lot! That worked. Yeah I did a sudo apt-get upgrade and somehow newer packages got installed on my Ubuntu 14.04. Am slowly trying to fix them one by one... T_T Does this by any chance affect my samba or ldap?Viewer
Since it is unknown what exactly the changes were it is unknown what impact they might have.Brassiere
F
16

It's a deprecation warning indicating the code will stop working in the future.

If you want to match a { literally, you should escape it.

In other words, you can fix the issue (silencing the warning) by replacing the first { with \{.

Facesaving answered 3/4, 2017 at 4:42 Comment(3)
escaping the { isn't always the best solution. sometimes {,n} is used instead of {0,n} to indicate 0..n repetitions. this used to work, now the 0 is no longer optional.Catalogue
@cas, Fixed. . .Facesaving
Works perfect!!Semantic
C
-2

Instead of escaping the left or right brace, how about using its unicode equivalent value? Like so:

while ($rest =~ m/^(.*?)(\\)?\$\x7B([^\x7B\x7D]+)\x7D(.*)$/sg) {

I had the similar problem, and this solved it for me.

Carbarn answered 22/6, 2018 at 1:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.