Avoid testing the same regular expression twice

Closes #314