Improve matching of path/hash and last chars

Based on #59, fixes #58
Merge pull request #60 from blueyed/match-hash-lastchar

Improve matching of path/hash and last chars