Before this regular expression was not designed to match all if/elseif statements, only those with $VAR or .var or !VAR in them because they needed some replacements done on them.

Then I made this regex replace ELSE IF with ELSEIF by adding the \s? between the (ELSE)? and IF (which it would match, but not save for the output).

But with the rest of the match, ((.*)[\s][\$|\.|!]([^\s]+)(.*)), meant that ELSE IF would only be replaced with ELSEIF on statements with $VAR or .var or !VAR in them. That's why I changed it to (.+?), so it would run for all elseif/else if/if statements.