in reply to regex help!
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 |