in reply to Parse a block of text

Put parenthesis around the part you want

if (/^(Info I want.+)Start of Info/) { print $1 ; }

Try that.

<(^.^-<) <(-^.^<) <(-^.^-)> (>^.^-)> (>-^.^)>

Replies are listed 'Best First'.
Re^2: Parse a block of text
by JadeNB (Chaplain) on Jul 07, 2008 at 21:04 UTC
    if (/^(Info I want.+)Start of Info/) { print $1 ; }
    This still grabs the 'Info I want' part, which doesn't seem (despite the name) to be part of the desired info. Thus, exclude it. Meanwhile, we might as well make this a multi-line regular expression with the /m flag, so that the /./ can gobble up new-lines (which seems to be desired); explicitly notice that the Info I want and Start of Info should be on their own lines; and allow there to be nothing at all between the markers (unless we don't want that). This gives:
    print $1 if ( /^Info I want$(.*)^Start of Info$/m )
    (Of course, this makes the end-of-section marker 'Start of Info', which is slightly different from what the original poster said.) It's easy to gobble up leading and trailing new-lines, if they're not significant:
    print $1 if ( /^Info I want\n+(.*?)\n+Start of Info$/m )
    (Note the non-greedy quantifier.) Of course, this only fetches one occurrence of the info; if there might be many occurrences, then we can use a lazy quantifier as above with a while loop and the /g flag. If the original poster can change the format of the input files, then it might be appropriate to consider changing the markers and using Text::Balanced.

      Ah right - the multiline flag. Forgot about that.

      Thanks for correcting me.

      <(^.^-<) <(-^.^<) <(-^.^-)> (>^.^-)> (>-^.^)>