Can't you factor out the ^$ to the start and end of the pattern?

The canonical hook also considers lines starting with a space to be a footer, because these are often continuation lines of the prior line.