Regexp不适用于Perl中的特定特殊字符

Pit*_*kos 6 regex unicode perl special-characters

我无法摆脱字符串中的特殊字符¤:

$word = 'c?i¤r$c?u¨s';
$word =~ s/[^a-zöäåA-ZÖÄÅ]//g;
printf "$word\n";
Run Code Online (Sandbox Code Playgroud)

在第二行,我尝试从字符串中删除任何非字母字符$word.我希望打印出马戏团这个词,但我得到:

ci?rc?us
Run Code Online (Sandbox Code Playgroud)

表达式中的öäåÖÅ只是我需要的瑞典字母表中的普通字符.

cho*_*oba 11

如果字符在您的源代码中,请务必use utf8.如果从文件中读取它们,binmode $FILEHANDLE, ':utf8'.

一定要阅读perldoc perlunicode.