7

This code:

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

prints

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

but this code

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

prints only:

The regular expression:



matches as follows:
  
NODE                     EXPLANATION
----------------------------------------------------------------------

What's wrong?

clt60
  • 62,119
  • 17
  • 107
  • 194
  • I don't have an actual answer but have you tried [Regexp::Debugger](http://search.cpan.org/perldoc?Regexp%3A%3ADebugger)? – stu42j Sep 10 '12 at 21:07
  • 1
    Seems to be the [unicode_strings feature](http://www.perl.com/pub/2011/06/new-features-of-perl-514-unicode-strings.html). You get the same behaviour with `use feature "unicode_strings";` – stu42j Sep 10 '12 at 21:18

1 Answers1

7

Feature unicode_strings changes which pattern gets created.

$ 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 can't handle many new (and not so new) features due to lack of maintenance. This is documented in the LIMITATIONS section.

I bet it gets the flags using re::regexp_pattern (explaining why it displays (?-imsx:d+) instead of (?^:\d+)), and chokes on the "u" flag it doesn't know about.

$ 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
ikegami
  • 367,544
  • 15
  • 269
  • 518