glob2regexp
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

glob2regexp

Build Status NPM version

Convert glob string to RegExp object

Usage

var globToRegExp = require("glob2regexp");
console.log(
    globToRegExp("http?://www.example.org").test("https://www.example.org")
); // true
console.log(
    globToRegExp("http{s,}://www.example.org").test("http://www.example.org")
); // true
console.log(
    globToRegExp("http{s,}://www.example.org").test("https://www.example.org")
); // true
 
 
// match a signle character
globToRegExp("?").test("a"); // true
 
// match any characters
globToRegExp("*").test(""); // true, match empty character
globToRegExp("*").test("a"); // true, match a signle character
globToRegExp("*").test("aa"); // true, match multiple characters
 
 
// also supports range match
globToRegExp("[0-9]").test("0"); // true
globToRegExp("[a-z]").test("z"); // true
 
 
// and supports brace-expansion
globToRegExp("{1,2}").test("1"); // true
globToRegExp("{1,2}").test("2"); // true
globToRegExp("{1,2}").test("3"); // false
globToRegExp("{,1}").test(""); // true
globToRegExp("{,1}").test("1"); // true

/glob2regexp/

    Package Sidebar

    Install

    npm i glob2regexp

    Weekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    15.6 kB

    Total Files

    7

    Last publish

    Collaborators

    • zbinlin