in reply to regex help!

Regular expressions find stuff you express. They don't find stuff that you don't express.

You should probably use some sort of scripting language that "wraps around" the regular expression engine, so that you can add some follow-up logic which is inconvenient for the regex engine to perform. Let's call that language Perl.

my $marker = qr/^ NP \s+ U \s+ Pu $/x; my $columns = qr/^ (\d+) \s+ (\d+) \s+ (\d+) $/x; while (<>) { # If we find our line with the column names, if (m/$marker/) { # Read the following line to look for their numbers. $_ = <>; if (m/$columns/) { print "NP = $1, U = $2, Pu = $3\n"; } else { print "Line after NP/U/Pu doesn't give numbers.\n"; } } }

You could just slurp the whole file and try to scan it for multiple-line patterns at once with a single regular expression, but you said "large output files" so I opted for the iterative solution so it wouldn't be limited by memory.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^2: regex help!
by QM (Parson) on Sep 15, 2005 at 15:30 UTC
    <nitpick>
    Just pointing out that the end of file may occur trying to do this:
    $_ = <>;
    I've done this before, and had the ubiquitous forehead-slapping-moment. Really need to check for this, because if the file ends at the wrong place, the <> will try to read from STDIN, which causes an annoying script/human deadlock.
    </nitpick>

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of