in reply to Re^2: Matching ranges
in thread Matching ranges

A slight bit more "regex kung-fu" is needed.

#!/usr/bin/perl -w use strict; my $num =1; while(<DATA>) { if ( (/^Services\s*$/../^Users\s*$/) =~ /^(\d+)(?<!^1)$/ ) { last if $1 <= $num++; #only first Services section next if /^====/ || /^\s*$/; #if you don't want these print "$_"; } } =prints blah glah sfsd asfsdf afsafdf =cut
Data Used:
__DATA__ ======================================================== Net Stuff ======================================================== slfjs sfafdds aslfkjsdl sfsdf ======================================================== Services ======================================================== blah glah sfsd asfsdf afsafdf ======================================================== Users ======================================================== Services sam bill frank
I highly recommend reading: not only Flipin good, or a total flop?, but some of the responses in that node that talk about eliminating start and end conditions - shows how to do "regex-fu" like above!

Replies are listed 'Best First'.
Re^4: Matching ranges
by ldbpm (Initiate) on Sep 02, 2010 at 15:12 UTC

    Sir, you are a true PerlMonk, with special kung-fu-regex skills. Thank you much!