remove duplicate forward slashes from the URL

后端 未结 4 1847
南方客
南方客 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 04:06

    This question has been answered before...

    var str = 'http://localhost//example/author/admin///';    
    var clean_url = str.replace(/([^:])(\/\/+)/g, '$1/');
    
    alert(clean_url);
    

    DEMO

提交回复
热议问题