@guy038 ,
^.*\Z
I knew that a single ^.*\Z could match zero characters; I intended it that way in case the last line of the file was an empty line (ie, a file that has a final newline). And that explains why one of the alternate versions that I played with but didn’t publish was off-by-one when I had that (though I didn’t put the two together at the time).
But I was suprised that ten instances of \Z (from (^.*\Z){10}) could match the single end of the file. I know it’s a “zero width” match, but I hadn’t thought about the fact that being “zero width” meant that two or more could match in a row. But yes, I justed tested, and confirmed that you can have a regex with multiple EOF in a row and have it still match… or multiple ^ or $ as well. Interestingly. \Z{10} is invalid, but (\Z){10} is allowed – so you cannot multiple a true zero-width expression (which makes sense), but if you have a group that happens to contain only a zero-width expression, you can multiply that expression.
Thanks for helping me learn something new today. :-)
(?-s)^.*\R(?=(?:^.*\R|.+\Z){10})
I was trying to avoid repeating myself with having to put the dots in both alternations. (?-s)^.*\R(?=(?:^.*(?:\R|.\Z)){10}) works just as well… but yours actually requires less typing, so my adherence to DRY made mine longer. :-)