Now you've really confused yourself. :)
Your tests are irrelevant in this case. I was using a
zero-width assertion. "foo" is not zero-width.
Just consider the second regex. That cannot be true, no matter what string you try it on. Because
(?=foo) looks if the next three chars are "foo", but then you at the same time try to match "bar". So that will
never be true.
What a look-behind does is just to set how many steps behind current position it should look. In your case it's three because "foo" is three bytes long. You might be familiar with that look-behinds cannot be variable length. This is closely related to that implementation. Besides that there's no fundamental difference between look-behinds and look-aheads. A look-ahead just steps zero steps back and hence start looking at the current position. The limitation of only being able to use a constant-width patterns for look-behinds is checked at regex compile-time, and at regex run-time the regex engine uses the same method for both types of assertions. Theoretically the look-ahead takes X steps back, it's just that X is always 0.
If the look-behind pattern then is zero-width, the engine takes zero steps back to start it's matching, and thus effectively is the same as a look-ahead.
Cheers,
-Anomo
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.