获取dirName
举例:输入:http://www.baidu.com/js/index.js
输出:http://www.baidu.com/js/
代码:
var DIRNAME_RE = /[^?#]*// // Extract the directory portion of a path // dirname("a/b/c.js?t=123#xx/zz") ==> "a/b/" // ref: http://jsperf.com/regex-vs-split/2 function dirname(path) { return path.match(DIRNAME_RE)[0] }
点:
[^?#] 不包含?和#的字符合辑
* 匹配任意次数,注意会匹配尽量多的内容(贪婪模式)
/ 匹配斜杠/