globToRegExp
Compiles a simple glob pattern into a RegExp that matches the whole string: * matches any
sequence of UTF-16 code units (including none), ? matches exactly one UTF-16 code unit.
Everything else is matched literally.
This is not a full shell/minimatch glob — no brace expansion, character classes, or
path-separator-aware **, just the two textbook wildcards. Like the rest of this library,
lengths are counted in UTF-16 code units: ? matches one code unit, not one Unicode code
point, so it matches only half of a surrogate pair (e.g. an emoji outside the Basic
Multilingual Plane).
Available since v3.1.1
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
pattern | string | The glob pattern to compile |
caseSensitive | boolean | Whether the resulting `RegExp` is case-sensitive. Defaults to `true`. |
Returns
Section titled “Returns”RegExp — A RegExp matching strings that satisfy pattern in full
Examples
Section titled “Examples”Match a file extension pattern
Section titled “Match a file extension pattern””*” matches any sequence of characters.
Match a fixed-width placeholder with ”?”
Section titled “Match a fixed-width placeholder with ”?”””?” matches exactly one character — handy for fixed-width codes.
Reuse the same pattern for many strings efficiently
Section titled “Reuse the same pattern for many strings efficiently”Compile the RegExp once and reuse it for every check instead of recompiling per candidate. If you also need to cache across many different call sites, wrap globToRegExp itself with memoize() from @helpers4/function.
