Correct regexp would be `/(.*)\n(.*\n)?/`... `m` only makes `.` match `\n`, which you don't need, and proper grouping allows to simplify code below.