In general, a \ (backslash) introduces a regex zero-width assertion. Some such are \A \B \b \Z \z and there are others. Why do you need backslashes in your paths? Even in Perl running under Windows, forwardslashes work just as well unless you need to construct a command that is to be given to the Windows shell. I don't recall what assertion \C used to be, but clearly Perl does.

Update 1:

... in m/C:\Book\ <-- HERE C0001-Chapter-001.mp3/ ...
Note that the \B assertion is also present in the
    m/C:\Book\C0001-Chapter-001.mp3/
regex with which you are trying to construct a match for a file name, so the regex will not match what you think it will even if \C was not a problem. Would a simple string equality eq comparator be better here? (Update: Oops... Forgot you want to do a substitution.)

Update 2: See quotemeta:

Win8 Strawberry 5.8.9.5 (32) Fri 08/19/2022 19:42:14 C:\@Work\Perl\monks >perl use strict; use warnings; my $txt = "C:\\Book\\C0001-Chapter-001.mp3"; my $new = "C:\\Book\\NEW-C0001-Chapter-001.mp3"; print "\n"; print "Before: '$txt' \n"; # Workaround -- use \Q \E -- see quotemeta. $txt =~ s/\Q$txt\E/$new/; print "After: '$txt' \n"; print "\n"; ^Z Before: 'C:\Book\C0001-Chapter-001.mp3' After: 'C:\Book\NEW-C0001-Chapter-001.mp3'


Give a man a fish:  <%-{-{-{-<


In reply to Re: Unexpected Error: \C no longer supported in regex (updated x2) by AnomalousMonk
in thread Unexpected Error: \C no longer supported in regex by roho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.