Dear monks,

using the following code

print "- " =~ /\s*\p{Dash}\s*/; # 1 print "- " =~ /\s*\p{Dash}{1}\s*/; # 2 print "- " =~ /\s*-\s*/; # 3
only line 2 and 3 matches. Debugging the regex makes clear why:
Compiling REx "\s*\p{Dash}\s*" synthetic stclass "ANYOF[\11\12\14\15 ][{unicode_all}+utf8::Dash]". Final program: 1: STAR (3) 2: SPACE (0) 3: ANYOF[{unicode}+utf8::Dash] (15) 15: STAR (17) 16: SPACE (0) 17: END (0) stclass ANYOF[\11\12\14\15 ][{unicode_all}+utf8::Dash] minlen 1 Matching REx "\s*\p{Dash}\s*" against "- " Matching stclass ANYOF[\11\12\14\15 ][{unicode_all}+utf8::Dash] agains +t "- " (2 chars) 1 <-> < > | 1:STAR(3) SPACE can match 1 times out of 21474 +83647... 2 <- > <> | 3: ANYOF[{unicode}+utf8::Dash](15) failed... 1 <-> < > | 3: ANYOF[{unicode}\-...+utf8::Dash](1 +5) failed... failed... Contradicts stclass... [regexec_flags] Match failed Freeing REx: "\s*\p{Dash}\s*"

The first \s* matches the second character of "- " and the \p{Dash} fails, since the regex does not backtrack beyond the last space. But shouldn't there be a match?

Version 3 obviously matches because of some optimization (seraching for "-"), but why does Version 2 match, since it should be equivalent to 1?

Is this a bug or does my first regex simply not do what I think?

Cheers, Andrew


In reply to Strange re behaviour for /\s*\p{Dash}\s*/ - bug or feature? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.