在Perl中匹配多个括号实例时遇到麻烦

时间:2013-11-26 15:54:34

标签: regex perl

以下是我想要获得的一个例子:

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>

1 个答案:

答案 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\)/;