Ruby regex: replace double slashes in URL -
i want replace multiple slashes in url, apart in protocol definition ('http[s]://', 'ftp://' , etc). how do this?
this code replaces without exceptions:
url.gsub(/\/\/+/, '/')
you need exclude match preceeded :
url.gsub(/([^:])\/\//, '\1/')
Comments
Post a Comment