in reply to How do I match the closest of repeated strings?

Alternative:

m{ ( ^abc$ (?:(?!^def$).)* ^def$ ) }smx

Replies are listed 'Best First'.
Re^2: How do I match the closest of repeated strings?
by moritz (Cardinal) on Sep 29, 2008 at 09:50 UTC
    That will match everything from the first abc to the first def, not not everything starting from the closest abc (which I believe is what the OP wants).

    But it can be adapted, of course:

    m{ ( ^abc$ (?:(?!^(?:def|abc)$).)* ^def$ ) }smx