【问题标题】:YAPE::Regex::Explain not working with use 5.014;YAPE::Regex::Explain 不适用于使用 5.014;
【发布时间】:2022-04-06 22:34:24
【问题描述】:

这段代码:

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
----------------------------------------------------------------------

怎么了?

【问题讨论】:

标签: regex perl


【解决方案1】:

功能 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

【讨论】:

    猜你喜欢
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多