Improve the regex that handles absolute paths.

This should not choke on small directory names, like "pg".

Thanks to @elyscape for pointing out a better way of doing this.