javascript: remove duplicate slashes and trailing slash -
javascript how remove duplicate slashes , trailing slash using regex?
example:
origin url:
http://localhost:8080////app//user/login/// to
http://localhost:8080/app/user/login i think question show powerful regex, don't understand why people vote against me , close question. closer must don't know best answer!!!
here simple regex based approach.
var url = 'http://localhost:8080////app//user/login///'; var sanitized = url .replace(/^http\:\/\//, '') // remove leading http:// (temporarily) .replace(/\/+/g, '/') // replace consecutive slashes single slash .replace(/\/+$/, ''); // remove trailing slashes url = 'http://' + sanitized; // url contains "http://localhost:8080/app/user/login"
Comments
Post a Comment