美文网首页
glob使用指南

glob使用指南

作者: lcfme | 来源:发表于2017-12-26 17:09 被阅读0次

    globs是一种模式匹配,如在命令行使用ls *.js或者如在.gitignore中添加build/*。
    在解析路径之前,如果模式中有大括号,包裹的部分将被展开运算。如a{b/c/d,bcd}将被展开可以匹配到a/b/c/d和abcd。

    常见的匹配符号

    * 匹配0个或多个字符。如./.js,匹配统计目录中所有的js文件。
    ? 匹配1个字符
    [...] 匹配一个范围的字符,类似于正则表达式。如果中括号中第一个字符是!或^,代表匹配不再这个范围内的字符。
    ** 匹配任意路径 如:./
    //js,可以匹配到./a.js也可以匹配到./a/b.js。
    !(pattern|pattern|pattern) Matches anything that does not match any of the patterns provided.
    ?(pattern|pattern|pattern) Matches zero or one occurrence of the patterns provided.
    +(pattern|pattern|pattern) Matches one or more occurrences of the patterns provided.
    (a|b|c) Matches zero or more occurrences of the patterns provided
    @(pattern|pat
    |pat?erN) Matches exactly one of the patterns provided

    glob常用的方法

    glob(pattern, [options], cb)
    如:

        glob('./**/*.js, (err, files) => {
            // files 是一个数组,每一项是匹配到的文件名,即项目中所有的js文件。
        }
    

    相关文章

      网友评论

          本文标题:glob使用指南

          本文链接:https://www.haomeiwen.com/subject/ssdjgxtx.html