You'll likely either need a big-time regex (where's Darryl when you need him?) or you'll need to step through the text one line at a time yourself doing a simple parsing of the text.

Edit: I'm wrong. You need to use booleans here to change the state of your program depending on whether you've passed "ab" and not "/ab". Perhaps only two boolean variables, abStart and abEnd, but no fancy regex is needed. Why not give it a try?

Edit: wrong again. You can do this with only one boolean variable. And most importantly, you only read one token each time through your loop. It's all about the logic, the boolean logic. :)