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

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

Replies are listed 'Best First'.
Re^3: grabbing chunks of text
by ikegami (Patriarch) on Mar 10, 2010 at 18:59 UTC

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

        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.