Unescaped left brace regex error

TheCabDriverCheatedMeToday picture TheCabDriverCheatedMeToday · Apr 2, 2017 · Viewed 16.4k times · Source

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) {

Answer

ikegami picture ikegami · Apr 3, 2017

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 \{.