in reply to grabbing chunks of text

@blocks = /:\w.*? type = .*?(?=:\w)/sg;

You need zero-width lookahead for the final :\w substring. Otherwise it will already have been consumed and no longer available when the next match attempt starts.  Also, you need option /g for "global" matching.

Replies are listed 'Best First'.
Re^2: grabbing chunks of text
by spencerd (Novice) on Mar 10, 2010 at 18:38 UTC
    almut That grabbed the chunks of text I was looking for but it also grabbed the chunk from :OBFCYCXYE12S to :iohstl152dax which I was trying to exclude because there is not "type =" in the middle of it

      .* 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.

        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;