...has a mode where it scans through the string backwards...

The way I see it, is that the whole regular expression engine should be able to go either forward or backward. At any point of its execution. To be really able to have variable length look-behind.

(?<=foo.*?) # if there is a "foo" before the match
is but the beginning. How about:
<?<=foo.*?(?=.*?bar)) # if there is a "foo" before, with a "bar" afte +r it

To do this properly, you would need to rewrite the whole regex engine, I'm afraid (and what I remember from one of MJD's talks about how he hacked the regular expression engine). This may/will happen for Perl6. So I guess we'll have to hold our breath until then.

Meanwhile, I wonder whether you wouldn't be able to hack something with (?{code}) and/or (??{code}), grabbing the string before the match so far, reversing it and feeding that a reversed regex. Possibly in combination with a source filter.

Hmmm... maybe I shouldn't have these evil thoughts this early in the morning. ;-)

Liz


In reply to Re: Re: Re: Why do zero width assertions care about lookahead/behind? by liz
in thread Why do zero width assertions care about lookahead/behind? by davido

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.