开发者

How to replace www. from url without breaking urls like www.someurlwww.com

开发者 https://www.devze.com 2023-01-24 01:06 出处:网络
I have been using .replace(\"www.\", 开发者_运维技巧\"\"); in javascript, but today I was thinking that if an url contains www. in the last part (like someurlwww.com), that will also get replaced. How

I have been using .replace("www.", 开发者_运维技巧""); in javascript, but today I was thinking that if an url contains www. in the last part (like someurlwww.com), that will also get replaced. How can I safely cleanup urls protocol+www.?


Try with

.replace(/^http:\/\/www./, "http://")
.replace(/^www./, "")


http://jsfiddle.net/PePS7/7/

this should do the trick

value.replace(/[https*:\\]*www./,""));       
0

精彩评论

暂无评论...
验证码 换一张
取 消