Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Last active February 3, 2018 05:56
Show Gist options
  • Save jonschlinkert/ef4ee3bab2d78b50b323 to your computer and use it in GitHub Desktop.
Save jonschlinkert/ef4ee3bab2d78b50b323 to your computer and use it in GitHub Desktop.

Regex comparison

In both micromatch and minimatch, globs are converted to regex, which is then used for matching supplied values.

The following example shows one of the implementation differences between micromatch and minimatch, as a way of demonstrating how micromatch manages to have better Bash support while also being 20-120x faster than minimatch.

Pattern

Given this glob pattern:

a/{b..s}/b/*-{01..10}.js

Micromatch

This is the regex created by micromatch:

/^(?:a/[b-s]/b/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-[01-10]\.js)$/

Minimatch

This is the regex created by minimatch:

/^(?:a\/b\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-01\.js|a\/b\/b\/(?!(?:^|\
/)\.{1,2}(?:$|\/))(?=.)[^/]*?-02\.js|a\/b\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)
[^/]*?-03\.js|a\/b\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-04\.js|a\/b\/b\/
(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-05\.js|a\/b\/b\/(?!(?:^|\/)\.{1,2}(?:$|
\/))(?=.)[^/]*?-06\.js|a\/b\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-07\.js|
a\/b\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-08\.js|a\/b\/b\/(?!(?:^|\/)\.{
1,2}(?:$|\/))(?=.)[^/]*?-09\.js|a\/b\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*
?-10\.js|a\/c\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-01\.js|a\/c\/b\/(?!(?
:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-02\.js|a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\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-08\.js|a\/r\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(
?=.)[^/]*?-09\.js|a\/r\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-10\.js|a\/s\
/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-01\.js|a\/s\/b\/(?!(?:^|\/)\.{1,2}(
?:$|\/))(?=.)[^/]*?-02\.js|a\/s\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-03\
.js|a\/s\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-04\.js|a\/s\/b\/(?!(?:^|\/
)\.{1,2}(?:$|\/))(?=.)[^/]*?-05\.js|a\/s\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[
^/]*?-06\.js|a\/s\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-07\.js|a\/s\/b\/(
?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-08\.js|a\/s\/b\/(?!(?:^|\/)\.{1,2}(?:$|\
/))(?=.)[^/]*?-09\.js|a\/s\/b\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?-10\.js)$
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment