in reply to Re^2: grabbing chunks of text
in thread grabbing chunks of text

.* is too permissive. You could use a complicated trick to fix this, but it's easiest to extract the blocks then to filter out the ones you don't want.

@blocks = grep / type =/, /:\w.*?(?=:\w)/sg;
If you want to break the blocks at the start of the line, the following will do that for you:
@blocks = grep / type =/, /^[^:]*:\w.*\n(?:[^:]*: .*\n)*/mg;

It also demonstrates how lookahead and the non-greedy modifier can be avoided here.

Replies are listed 'Best First'.
Re^4: grabbing chunks of text
by spencerd (Novice) on Mar 10, 2010 at 19:12 UTC
    This is a bit crazy and I dont understand it completly I just pieced it together from stuff people posted on chatterbox seems to work though
    my @blocks = $file_contents =~ /:\w(?:(?!:\w).)*?type\s*=(?:(?!:\w).) +*?(?=:\w)/sg;

      This is a bit crazy and I dont understand it completly

      That's the complicated trick I mentioned. I don't see any advantage to doing it this way.