in reply to Re: multi-line regexp
in thread multi-line regexp

hi

your code's working here and its looks nice (at least for me), tobe honest i need more times to understand your code, i wish you can explain the process of your code (while i am reading my notes about pattern matching)

Anyway i tried other ways, and so far i made a litle code like :

$str = "aa\nbb\ncc\naa\ndd\nee\n"; @a = ($str =~ /aa\n.*\n.*/g); print "1 = $a[0]\n2 = $a[1]\n";
And the other is :
$str = "aa\nbb\ncc\naa\ndd\nee\n"; @a = ($str =~ /(aa.*).?(aa.*)/gs); print "1 = $a[0]\n2 = $a[1]\n";

But anyway, prasadbabu code's nicer, that's why i asked for the explanation, or do you see something bad in my code ?

Update : pKai code simpler and easy to understand for me :)

thanks, zak

Replies are listed 'Best First'.
Re^3: multi-line regexp
by pKai (Priest) on Dec 21, 2005 at 18:25 UTC
    Well, this code of yours makes some very specific assumptions about the input string:
    • /aa\n.*\n.*/g assumes, that every aa-line is followed by exactly 2 other lines which have to be extracted in addition to the aa-lead.
    • /(aa.*).?(aa.*)/gs extracts exactly 2 fields from the string beginning with aa.
    The regexes with look-ahead where proposed to cover a wider range of input strings.