从网址中删除重复的正斜杠 [英] remove duplicate forward slashes from the URL
本文介绍了从网址中删除重复的正斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从网址中删除重复的正斜杠,但要保留//在http:
之后的//,以使网址不会中断.
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://localhost//example/author/admin///
应该是
http://localhost/example/author/admin/
我正在尝试此操作,但是它将仅删除最后一个斜杠.我要删除所有双精度字
I'm trying this, but it will remove only the last slash. I want to remove all double
abc = 'http://localhost//example/author/admin///';
clean_url = abc.replace(/\/$/,'');
alert(clean_url);
以下仅检查三个斜杠.
clean_url = abc.replace("///", "");
alert(clean_url);
我要删除所有重复的斜杠.
I want to remove all the duplicate slashes.
推荐答案
您可以使用:
abc.replace(/([^:]\/)\/+/g, "$1");
Working Demo
更新: 已由Halcyon回答
Update: Already answered by Halcyon
这篇关于从网址中删除重复的正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文