Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
To elaborate a bit what should probably be happening is that the regex engine should always backtrack on .* into the equivalent of NOTHING, but instead it commits to the match and fails under /m once it reaches \n.
perl5.9.5 -Mre=debug -e 'my @re = (qr/.*\z/, qr/.?\z/, qr/(|.+)\z/); "\n" ~~ $_ for @re'

Compiling REx ".*\z"
Final program:
   1: STAR (3)
   2:   REG_ANY (0)
   3: EOS (4)
   4: END (0)
floating ""$ at 0..2147483647 (checking floating) anchored(MBOL) implicit minlen 0 
Compiling REx ".?\z"
Final program:
   1: CURLY {0,1} (4)
   3:   REG_ANY (0)
   4: EOS (5)
   5: END (0)
floating ""$ at 0..1 (checking floating) minlen 0 
Compiling REx "(|.+)\z"
Final program:
   1: OPEN1 (3)
   3:   BRANCH (5)
   4:     NOTHING (8)
   5:   BRANCH (FAIL)
   6:     PLUS (8)
   7:       REG_ANY (0)
   8: CLOSE1 (10)
  10: EOS (11)
  11: END (0)
floating ""$ at 0..2147483647 (checking floating) minlen 0 
Guessing start of match in sv for REx ".*\z" against "%n"
Found floating substr ""$ at offset 0...
Position at offset 0 does not contradict /^/m...
Guessed: match at offset 0
Matching REx ".*\z" against "%n"
   0 <> <%n>                 |  1:STAR(3)
                                  REG_ANY can match 0 times out of 2147483647...
   0 <> <%n>                 |  3:  EOS(4)
                                    failed...
                                  failed...
Match failed
Guessing start of match in sv for REx ".?\z" against "%n"
Found floating substr ""$ at offset 0...
Guessed: match at offset 0
Matching REx ".?\z" against "%n"
   0 <> <%n>                 |  1:CURLY {0,1}(4)
                                  REG_ANY can match 0 times out of 1...
   0 <> <%n>                 |  4:  EOS(5)
                                    failed...
                                  failed...
   1 <%n> <>                 |  1:CURLY {0,1}(4)
                                  REG_ANY can match 0 times out of 1...
   1 <%n> <>                 |  4:  EOS(5)
   1 <%n> <>                 |  5:  END(0)
Match successful!
Guessing start of match in sv for REx "(|.+)\z" against "%n"
Found floating substr ""$ at offset 0...
Guessed: match at offset 0
Matching REx "(|.+)\z" against "%n"
   0 <> <%n>                 |  1:OPEN1(3)
   0 <> <%n>                 |  3:BRANCH(5)
   0 <> <%n>                 |  4:  NOTHING(8)
   0 <> <%n>                 |  8:  CLOSE1(10)
   0 <> <%n>                 | 10:  EOS(11)
                                    failed...
   0 <> <%n>                 |  5:BRANCH(8)
   0 <> <%n>                 |  6:PLUS(8)
                                  REG_ANY can match 0 times out of 2147483647...
                                  failed...
   1 <%n> <>                 |  1:OPEN1(3)
   1 <%n> <>                 |  3:BRANCH(5)
   1 <%n> <>                 |  4:  NOTHING(8)
   1 <%n> <>                 |  8:  CLOSE1(10)
   1 <%n> <>                 | 10:  EOS(11)
   1 <%n> <>                 | 11:  END(0)
Match successful!
Freeing REx: ".*\z"
Freeing REx: ".?\z"
Freeing REx: "(|.+)\z"

In reply to Re: Strange regex to test for newlines: /.*\z/ by avar
in thread Strange regex to test for newlines: /.*\z/ by betterworld

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-23 23:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found