1. ^\n matches an empty line (and by empty I mean EMPTY ;) 2. ^\s*?\n matches lines that are empty or contain only whitespace 3. ^\s*\n matches *groups of 1 or more consecutive lines* that are empty or contain only whitespace
I think (and experiments show that) $ before \n is superfluous. (the difference btw. 2 and 3 is in the non-greedy "?" modifier, but I'm not good enough at regexes to explain you the Arcane Secrets :)
ciao,
Domenico