Home: Perl Programming Help: Regular Expressions:
matching n lines after regular expression



jnijjar
New User

Apr 29, 2010, 4:40 PM


Views: 5441
matching n lines after regular expression

I want to match n number of lines after the regular expression match.

Input Data:

Thurs 2010
A
B
C
Friday 2010
D
E
F
Saturday 2010
G
H
I

I want to match:

Friday 2010
D
E
F

So something like:

if (/friday/i) {

#printing Friday 2010 and three lines after

}


rovf
Veteran

Apr 30, 2010, 12:12 AM


Views: 5432
Re: [jnijjar] matching n lines after regular expression

(1) Would the .. operator help? See perldoc perlop.

(2) Do you need to process the input one line at a time? If you can afford storing the whole input into a string, you could also match something like /Friday\n((?:[^\n]*\n){3})/m