Perl字符串匹配不应该失败

Rak*_*esh 1 perl string-comparison

我的脚本中有以下代码.

if($description =~ /\'/) {
    print "I am here\n";    
    $description =~ s/\'/'/g;
}
print "description = $description\n";
Run Code Online (Sandbox Code Playgroud)

当我运行这个脚本时,"I am here\n"由于比较失败,我没有得到输出.

但是,当$description字符串确实包含撇号时.

$description = "The baseball player’s spiritual redemption and recovery from drug addiction.";

上下文:我正在解析从调用nytimes bestsellers api(以json格式返回)获得的字符串,并且此字符串存储在$description字符串中.

Ala*_*rry 6

您的示例字符串不包含撇号.它包含一个U+2019 RIGHT SINGLE QUOTATION MARK.

它应该匹配 /\x{2019}/