in reply to Regular expression...

Personally, I would just use the loop.

Yes, it is possible to use regular-expression tricks such as the /m (and /g) operators, but I also caution that “clarity, clarity usually wins the race.”

You know that you are reading from a file-buffer (so a loop is not really “slower”), and you also know that a line-by-line approach can easily handle an arbitrary number of lines.   Plus, it is clear, and easily changed.   The programmers who come after you (or who work alongside you) can easily understand what old fashioned, loop-based code is now doing, and they can make changes to it with confidence.   When, not if, the requirements change, they can change the code with much less fear of breaking it.