in reply to Unexpected Error: \C no longer supported in regex

G'day roho,

I see you've got a solution using quotemeta. Here's some additional information.

A '\C' used to match a single byte. Last documented in "perlrebackslash v5.22.4: All the sequences and escapes".

It was removed in v5.24 according to "perl5240delta: The /\C/ character class has been removed."; however, although documented as such, [perl #41916] indicates this didn't happen until v5.26.

Use of '\C' is now fatal in regexes (as you've found out) and gives a warning in strings:

$ perl -wE 'say "p" =~ /\C0/ ? "Y" : "N"' \C no longer supported in regex; marked by <-- HERE in m/\ <-- HERE C0 +/ at -e line 1. $ perl -wE 'say "\C0"' Unrecognized escape \C passed through at -e line 1. C0

Probably also worth a mention is the lowercase '\c'.

It's documented, with a fair amount of detail, in "perlop: Quote and Quote-like Operators: Note 5".

Some restrictions on its use were introduced in v5.20 — see "perl5200delta: Quote-like escape changes".

Depending on what character follows '\c', you may get a warning with useful information.

$ perl -wE 'say "\c0"' "\c0" is more clearly written simply as "p" at -e line 1. p $ perl -wE 'say "p" =~ /\c0/ ? "Y" : "N"' "\c0" is more clearly written simply as "p" in regex; marked by <-- HE +RE in m/\c0 <-- HERE / at -e line 1. Y

[I used Perl v5.36 for all of the example code above.]

— Ken

Replies are listed 'Best First'.
Re^2: Unexpected Error: \C no longer supported in regex
by roho (Bishop) on Aug 22, 2022 at 05:36 UTC
    Thank you for the additional information kcott. I appreciate everything that leads me to a better understanding of regexes.

    "It's not how hard you work, it's how much you get done."