in reply to Regex substituion eating newlines

You could replace "|$" with "|\n\z"; the "\z" matches the end of string, irrespective of newlines.

Update: originally I had "|\n\z" as the proposed replacement for "|$", but right after posting I realized that the preceding "\s*" made the \n superfluous.

Update 2: Sheesh. My original was right after all; leaving out the "\n" would result in the same problem that the OP posted about in the first place. Hypoglycemia is setting in; time to get me some breakfast.

the lowliest monk