Strange behaviour of REGEX in a WordPress filter (trying to suppress emtpy paragraphs)

In your first example, your regex is \s, which will match a whitespace character. In the second example, you have \s*, which will match zero or more whitespace characters. You’re probably looking for \s+, one or more whitespace characters.