正则-seajs中的正则

获取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]
}

点:

  [^?#]   不包含?和#的字符合辑

  *          匹配任意次数,注意会匹配尽量多的内容(贪婪模式)

       \/          匹配斜杠/

 

posted on 2017-09-21 17:22  王雪皓  阅读(168)  评论(0编辑  收藏  举报