小编llo*_*oyd的帖子

为什么这个正则表达式压制比我预期的要多?

我试图压制以[T 没有做正面匹配并否定结果的字符串.

my @tests = ("OT", "[T","NOT EXCLUDED");
foreach my $test (@tests)
{
 #match from start of string, 
 #include 'Not left sq bracket' then include 'Not capital T'
 if ($test =~ /^[^\[][^T]/)  #equivalent to /^[^\x5B][^T]/
 {
  print $test,"\n";
 }
}
Run Code Online (Sandbox Code Playgroud)

输出

NOT EXCLUDED
Run Code Online (Sandbox Code Playgroud)

我的问题是,有人可以告诉我为什么OT被排除在上面的例子中?

编辑 感谢您的答复到目前为止所有人,我可以看到我有点stoopid.

regex perl

1
推荐指数
1
解决办法
208
查看次数

标签 统计

perl ×1

regex ×1