Function globToRegExp
- glob
To (glob, options?): RegExpReg Exp Parameters
- glob: string
Glob string to convert.
- options: GlobOptions = {}
Conversion options.
Returns RegExp
The regular expression equivalent to the glob.
- glob: string
Glob string to convert.
Conversion options.
The regular expression equivalent to the glob.
Converts a glob string to a regular expression.
Tries to match bash glob expansion as closely as possible.
Basic glob syntax:
*- Matches everything without leaving the path segment.?- Matches any single character.{foo,bar}- Matchesfooorbar.[abcd]- Matchesa,b,cord.[a-d]- Matchesa,b,cord.[!abcd]- Matches any single character besidesa,b,cord.[[:<class>:]]- Matches any character belonging to<class>.[[:alnum:]]- Matches any digit or letter.[[:digit:]abc]- Matches any digit,a,borc.\- Escapes the next character for anosother than"windows".osset to"windows"./- Path separator.osset to"windows".Extended syntax:
{ extended: true }.?(foo|bar)- Matches 0 or 1 instance of{foo,bar}.@(foo|bar)- Matches 1 instance of{foo,bar}. They behave the same.*(foo|bar)- Matches n instances of{foo,bar}.+(foo|bar)- Matches n > 0 instances of{foo,bar}.!(foo|bar)- Matches anything other than{foo,bar}.Globstar syntax:
{ globstar: true }.**- Matches any number of any path segments.Note the following properties:
RegExpis anchored at both start and end.?(foo|bar/baz)is invalid. The separator will take precedence and the first segment ends with an unclosed group.Limitations:
!(foo|bar)will wrongly be converted to a negative look-ahead followed by a wildcard. This means that!(foo).jswill wrongly fail to matchfoobar.js, even thoughfoobaris notfoo. Effectively,!(foo|bar)is treated like!(@(foo|bar)*). This will work correctly if the group occurs not nested at the end of the segment.