I was fixing the bug discussed below, but I could take a slightly less-restrictive approach by using "[^\.\/]" instead of "[A-Za-z0-9]" which would still capture non-alphanumeric characters.

The restructuring is still needed, as the previous one doesn't do well when there's a dot in an extension but not in the filename.