This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse: make a complex pattern readable with /x
[perl5.git] / lib / B / Deparse.pm
index 0a68828..47b557d 100644 (file)
@@ -4825,7 +4825,23 @@ sub re_unback {
     my($str) = @_;
 
     # the insane complexity here is due to the behaviour of "\c\"
-    $str =~ s/(^|[^\\]|\\c\\)(?<!\\c)\\(\\\\)*(?=[[:^print:]])/$1$2/g;
+    $str =~ s/
+                # these two lines ensure that the backslash we're about to
+                # remove isn't preceeded by something which makes it part
+                # of a \c
+
+                (^ | [^\\] | \\c\\)             # $1
+                (?<!\\c)
+
+                # the backslash to remove
+                \\
+
+                # keep pairs of backslashes
+                (\\\\)*                         # $2
+
+                # only remove if the thing following is a control char
+                (?=[[:^print:]])
+            /$1$2/xg;
     return $str;
 }