remove duplicate forward slashes from the URL

后端 未结 4 1864
南方客
南方客 2021-01-04 03:34

How can I remove duplicate forward slashes from the a url, but keep the // which comes after http: so that the URL does not break.

http://localh         


        
4条回答
  •  忘掉有多难
    2021-01-04 03:44

    I know there're different answers solving the same problem, just another approach :)

    var s = "http://www.some-url.com//path//to";
    var res = s.replace(/(https?:\/\/)|(\/)+/g, "$1$2");
    

提交回复
热议问题