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

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -