in reply to Re: Replace not working
in thread Replace not working
The character class regex [^\s-~] matches any character that is not a whitespace character, a literal '-' (dash or hyphen) or a literal '~' (tilde). A 'Y' is not any of those characters, so it matches.
BTW — the character set [^\s-~] is better written as [^-\s~] so that the '-' character is not misunderstood (by the programmer or maintainer, not by Perl) as a character set range metacharacter. I'm guessing you are not running with warnings (and strictures), otherwise Perl would have complained about this:
>perl -wMstrict -le "my $rx = qr{ [^\s-~] }xms; print $rx;" False [] range "\s-" in regex; marked by <-- HERE in m/ [^\s- <-- HERE ~] / at -e line 1. (?msx-i: [^\s-~] )
|
|---|