Fix bug where file extension would not be detected correctly (e.g.
file.hello.c would be detected as having extension hello.c) because
the regular expression was too greedy.

A test case is included.