window.location.pathname 比如: /windows/location/page.html 我想得到“windows”,请问用正则表达式怎么写? var a="/windows/location/page.html"; var reg=/(^(http[s]?:\/\/[^\/]*\/)|(^\/))([^\/]+)\/.*$/ig; var t=a.replace(reg,"$4"); alert(a + "\n" + "\n" + t); var a=top.location + "/windows/location/page.html"; var t=a.replace(reg,"$4"); alert(a + "\n" + "\n" + t); alert(top.location + "\n" + "\n" + reg.test(top.location)); [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]