Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This is due to the nature of * and while it is a greedy quantifier, it is also quite a lazy quantifier. In this case \s* doesn't match any space, since it doesn't have to, and subsequently " MILE" is matched which doesn't match "MILE" so it's a successful match. Hopefully this quick oneliner and it's output should make that explanation clearer
shell> perl -Mre=debug -e '$_="1/2 MILE"; m{ 1/2 \s* (?!MILE) }x' Freeing REx: `,' Compiling REx ` 1/2 \s* (?!MILE) ' size 11 first at 1 1: EXACT <1/2>(3) 3: STAR(5) 4: SPACE(0) 5: UNLESSM[-0](11) 7: EXACT <MILE>(9) 9: SUCCEED(0) 10: TAIL(11) 11: END(0) anchored `1/2' at 0 (checking anchored) minlen 3 Guessing start of match, REx ` 1/2 \s* (?!MILE) ' against `1/2 MILE'.. +. Found anchored substr `1/2' at offset 0... Guessed: match at offset 0 Matching REx ` 1/2 \s* (?!MILE) ' against `1/2 MILE' Setting an EVAL scope, savestack=3 0 <> <1/2 MILE> | 1: EXACT <1/2> 3 <1/2> < MILE> | 3: STAR SPACE can match 1 times out of 32767... Setting an EVAL scope, savestack=3 4 <1/2 > <MILE> | 5: UNLESSM[-0] 4 <1/2 > <MILE> | 7: EXACT <MILE> 8 <1/2 MILE> <> | 9: SUCCEED could match... failed... 3 <1/2> < MILE> | 5: UNLESSM[-0] 3 <1/2> < MILE> | 7: EXACT <MILE> failed... 3 <1/2> < MILE> | 11: END Match successful! Freeing REx: ` 1/2 \s* (?!MILE) '

HTH

_________
broquaint


In reply to Re: regex negative lookahead behaviour by broquaint
in thread regex negative lookahead behaviour by shemp

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 browsing the Monastery: (2)
As of 2024-04-26 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found