从网址中删除域名(字符串) [英] Strip domain name from url (string)
本文介绍了从网址中删除域名(字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在访问样式表集合,如下所示:
I'm accessing the stylesheet collection like this:
var css = document.styleSheets[0];
它返回例如。 http://www.mydomain.com/css/main.css
问题:如何剥离域名只能获得 /css/main.css
?
Question: how can I strip the domain name to just get /css/main.css
?
推荐答案
这个正则表达式应该可以解决问题。它将替换使用空字符串找到的任何域名。还支持https://
This regular expression should do the trick. It will replace any domain name found with an empty string. Also supports https://
//css is currently equal to http://www.mydomain.com/css/main.css
css = css.replace(/https?:\/\/[^\/]+/i, "");
这将返回 /css/main.css
这篇关于从网址中删除域名(字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文