以下是我想要获得的一个例子:
my $a = "This is unsupported slot(s) or slot(s) reserved for another equipment";
my $b = "This is unsupported slot(?s) or slot(?s) reserved for another equipment";
if ($a =~ /$b/) {
print "yes\n";
} else {
print "no\n";
}
只要 $ b =“这是不受支持的插槽(?s)”,它就可以工作(打印是),但是当有超过1套要匹配的parantheses时,它不起作用。< / p>
答案 0 :(得分:5)
(?s)
表示其余模式匹配,就像使用了/s
一样。您希望$b
包含\(s\)
my $b = "This is unsupported slot\\(s\\) or slot\\(s\\)";
or
my $b = qr/This is unsupported slot\(s\) or slot\(s\)/;