in reply to Re^2: Why is variable length lookahead implemented while lookbehind is not?
in thread Why is variable length lookahead implemented while lookbehind is not?

My first thought for an "easy solution" is to generate a reversed version of the target string if there is a variable length look behind, then use the usual look ahead match processing on the reversed string starting at the "reversed" anchor point.

True laziness is hard work
  • Comment on Re^3: Why is variable length lookahead implemented while lookbehind is not?

Replies are listed 'Best First'.
Re^4: Why is variable length lookahead implemented while lookbehind is not?
by CountZero (Bishop) on Sep 07, 2011 at 21:11 UTC
    That is what is discussed at Variable-length lookbehind at dev.perl.org. The suggestion to write the variable-length lookbehind in right-to-left fashion was rejected as being obscure. The Perl regex-engine will have to do this reversing itself, which is not always possible or easy to do.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^4: Why is variable length lookahead implemented while lookbehind is not?
by ikegami (Patriarch) on Sep 07, 2011 at 20:51 UTC

    Reversing the string requires reversing the regex pattern too, and that's not trivial. For example, (?<=(.).*\1) would try to match \1.*(.), but \1 hasn't been populated yet.

    Update:

    ... What am I saying! Just have people write (.).*\1. That's what they'd have to do with a right-to-left parser too. I suspect all issues can be solved with proper documentation.