This is one of the reasons why I love this site. It very much seemed to me like a homework/interview question. Before you go asking for help, at least try it yourself!
/\ Sierpinski
Comment on Re^2: Searching for a string in a text and printing the next few lines