in reply to Re^3: using lookaround assertions to grab info
in thread using lookaround assertions to grab info

@m is an array of lines and some lines have multiple sections, ergo this exact code would not work. Or am I missing something?
  • Comment on Re^4: using lookaround assertions to grab info

Replies are listed 'Best First'.
Re^5: using lookaround assertions to grab info
by Ven'Tatsu (Deacon) on Jun 03, 2004 at 22:23 UTC
    It's very likely I could be wrong, I haven't tested it, but I think it would work.
    my $section = ''; foreach (@m) { if ( /^ #match the start of the line \s* #match 0 or more whitespace characters grab as many as we + can ( #start captureing [\w\s]*? #match 0 or more word or whitespace, grab as _few_ + as posible ) #end capture \s* #match 0 or more whitespace characters : #until we reach the a colon /x #x added for the comments && #if the match fails we don't bother checking $1 $1) { #check if we captured any thing if there was only whitesp +ace before the colon we won't have captured any thing $section = $1; #if we actualy found a section label save it } #$section should now be set to the last section label we found. if ($section eq '...') { ... }