A little refactoring of the if statements.

This means it has to check fewer things, and fixes an error
if the regular expression doesn't match.