Might want to use the Ruby `URI` class to do this as it may be more reliable than a regex.