CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



jnijjar
New User

Apr 29, 2010, 4:40 PM

Post #1 of 2 (2582 views)
matching n lines after regular expression Can't Post

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

Post #2 of 2 (2573 views)
Re: [jnijjar] matching n lines after regular expression [In reply to] Can't Post

(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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives