Could you look and see if there's something in the `Pathname` module that could handle this instead of the regular expressions?