in reply to multi-line regexp

This uses a minimum capture .*? and positive look ahead (?=...) with a conditional match aaaaa|$ to do the job:

#! /usr/bin/perl use strict; use warnings; my $str = "aaaaa\nbbbbb\nccccc\naaaaa\nddddd\neeeee\n" ; my @a = $str =~ /(aaaaa.*?)(?=aaaaa|$)/gs ; print join "\n", @a;

Prints:

aaaaa bbbbb ccccc aaaaa ddddd eeeee

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: multi-line regexp
by doctor_moron (Scribe) on Dec 21, 2005 at 20:41 UTC

    And i think in this case, there is no difference between :

    my @a = $str =~ /(aaaaa.*?)(?=aaaaa|$)/gs ;

    and

    my @a = $str =~ /aaaaa.*?(?=aaaaa|$)/gs ;
    right ?

      Interesting. Yes you are right and I've learned something. Thank you :)


      DWIM is Perl's answer to Gödel
        As far as I know lookarounds neither "eat" up any charakters nor do they save anything so it would just make sure to break the search, save its content in one cell of the array and go ahead because of global search.