Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Is this a bug?

The regexp debugger shows that in the /g case, the last match in the "implicit loop" of /g is a failed one (see also Repeated Patterns Matching a Zero length Substring), probably leading to that result in @-; note that $+ and $^N are also undef in this case. In addition to the below, try perl -MRegexp::Debugger -e '$_="a";s/(?=(a))/b/g'.

However, using those variables after a /g match feels a little sketchy to me, so this may be an XY problem, so if you could explain the bigger picture, perhaps we can help solve that.

$ perl -Mre=debug -e '$_="a";s/(?=(a))/b/g' Compiling REx "(?=(a))" Final program: 1: IFMATCH[0] (11) 3: OPEN1 (5) 5: EXACT <a> (7) 7: CLOSE1 (9) 9: SUCCEED (0) 10: TAIL (11) 11: END (0) minlen 0 Matching REx "(?=(a))" against "a" 0 <> <a> | 0| 1:IFMATCH[0](11) 0 <> <a> | 1| 3:OPEN1(5) 0 <> <a> | 1| 5:EXACT <a>(7) 1 <a> <> | 1| 7:CLOSE1(9) 1 <a> <> | 1| 9:SUCCEED(0) | 1| SUCCEED: subpattern success... 0 <> <a> | 0| 11:END(0) Match successful! Matching REx "(?=(a))" against "a" 0 <> <a> | 0| 1:IFMATCH[0](11) 0 <> <a> | 1| 3:OPEN1(5) 0 <> <a> | 1| 5:EXACT <a>(7) 1 <a> <> | 1| 7:CLOSE1(9) 1 <a> <> | 1| 9:SUCCEED(0) | 1| SUCCEED: subpattern success... 0 <> <a> | 0| 11:END(0) END: Match possible, but length=0 is smaller than requested=1, failing +! 1 <a> <> | 0| 1:IFMATCH[0](11) 1 <a> <> | 1| 3:OPEN1(5) 1 <a> <> | 1| 5:EXACT <a>(7) | 1| failed... | 0| failed... Match failed Freeing REx: "(?=(a))"

In reply to Re: Global match and capture group in look-ahead == under-populated "@-"? by haukex
in thread Global match and capture group in look-ahead == under-populated "@-"? 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":



  • 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 chilling in the Monastery: (7)
As of 2024-04-18 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found