8

这段代码:

use strict;
use warnings;
use YAPE::Regex::Explain;
print YAPE::Regex::Explain->new( qr/d+/ )->explain();

印刷

The regular expression:

(?-imsx:d+)

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  d+                       'd' (1 or more times (matching the most
                           amount possible))
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------

但是这段代码

use 5.014;  #added this
use strict;
use warnings;
use YAPE::Regex::Explain;
print YAPE::Regex::Explain->new( qr/d+/ )->explain();

仅打印:

The regular expression:



matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------

怎么了?

4

1 回答 1

7

特征unicode_strings改变了创建的模式。

$ perl -le'no  feature qw( unicode_strings ); print qr/\d+/'
(?^:\d+)

$ perl -le'use feature qw( unicode_strings ); print qr/\d+/'
(?^u:\d+)

由于缺乏维护, YAPE::Regex::Explain无法处理许多新的(而且不是那么新的)功能。这记录在限制部分。

我敢打赌它会使用re::regexp_pattern(解释为什么它显示(?-imsx:d+)而不是(?^:\d+))来获取标志,并扼杀u它不知道的“”标志。

$ perl -le'no  feature qw( unicode_strings ); print +(re::regexp_pattern(qr/\d+/))[1]'


$ perl -le'use feature qw( unicode_strings ); print +(re::regexp_pattern(qr/\d+/))[1]'
u
于 2012-09-10T21:22:42.027 回答