in reply to Re: Pattern matching fails because of special characters
in thread Pattern matching fails because of special characters

You can't escape with backslashes inside a character class.
Put the minus at the end and drop all backslashes, unless you want to match \ .

A counterexample:

c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'abc\ZD+A-G\HJxyz'; print qq{'$s'}; ;; $s =~ m{ ([A\-Z\+GD]+) }xms; print qq{'$1'}; " 'abc\ZD+A-G\HJxyz' 'ZD+A-G'
(But I agree that putting the - at the end and dropping the backslashes would have the same effect.)


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

Replies are listed 'Best First'.
Re^3: Pattern matching fails because of special characters
by LanX (Saint) on Jun 10, 2019 at 01:25 UTC
    you are right

    perlrecharclass#Special-Characters-Inside-a-Bracketed-Character-Class

    Characters that may carry a special meaning inside a character class are: \ , ^ , - , and , and are discussed below. They can be escaped with a backslash, although this is sometimes not needed, in which case the backslash may be omitted.

    Mea culpa!

    (time to retire? :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    PS: I'm afraid perldoc.perl.org "improved" to the worse.