DotNet.Glob 2.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNet.Glob --version 2.0.3                
NuGet\Install-Package DotNet.Glob -Version 2.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNet.Glob" Version="2.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNet.Glob --version 2.0.3                
#r "nuget: DotNet.Glob, 2.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotNet.Glob as a Cake Addin
#addin nuget:?package=DotNet.Glob&version=2.0.3

// Install DotNet.Glob as a Cake Tool
#tool nuget:?package=DotNet.Glob&version=2.0.3                

DotNet.Glob

A fast (probably the fastest) globbing library for .NET.

Branch Build Status NuGet
Master Build master NuGet
Develop Build status NuGet

This library does not use Regex - I wanted to make something much faster. The latest benchmarks show that DotNet.Glob signficantly outperforms Regex. The benchmarks use BenchmarkDotNet and can be located inside this repo. Just dotnet run them. Some Benchmark results have also been published on the wiki: https://github.com/dazinator/DotNet.Glob/wiki/Benchmarks-(vs-Compiled-Regex)

Usage

  1. Install the NuGet package. Install-Package DotNet.Glob
  2. Add using statement: using DotNet.Globbing;
  3. Parse a glob from a pattern
 var glob = Glob.Parse("p?th/*a[bcd]b[e-g]a[1-4][!wxyz][!a-c][!1-3].*");
 var isMatch = glob.IsMatch("pAth/fooooacbfa2vd4.txt");

Build a glob fluently

You can also use the GlobBuilder class if you wish to build up a glob using a fluent syntax. This is also more efficient as it avoids having to parse the glob from a string pattern.

So to build the following glob pattern: /foo?\\*[abc][!1-3].txt:


  var glob = new GlobBuilder()
                .PathSeperator()
                .Literal("foo")
                .AnyCharacter()
                .PathSeperator(PathSeperatorKind.BackwardSlash)
                .Wildcard()
                .OneOf('a', 'b', 'c')
                .NumberNotInRange('1', '3')
                .Literal(".txt")
                .ToGlob();

   var isMatch = glob.IsMatch(@"/fooa\\barrra4.txt"); // returns true.

Patterns

The following patterns are supported (from wikipedia):

Wildcard Description Example Matches Does not match
* matches any number of any characters including none Law* Law, Laws, or Lawyer
? matches any single character ?at Cat, cat, Bat or bat at
[abc] matches one character given in the bracket [CB]at Cat or Bat cat or bat
[a-z] matches one character from the range given in the bracket Letter[0-9] Letter0, Letter1, Letter2 up to Letter9 Letters, Letter or Letter10
[!abc] matches one character that is not given in the bracket [!C]at Bat, bat, or cat Cat
[!a-z] matches one character that is not from the range given in the bracket Letter[!3-5] Letter1, Letter2, Letter6 up to Letter9 and Letterx etc. Letter3, Letter4, Letter5 or Letterxx

In addition, DotNet Glob also supports:

Wildcard Description Example Matches Does not match
** matches any number of path / directory segments. When used must be the only contents of a segment. /**/some.* /foo/bar/bah/some.txt, /some.txt, or /foo/some.txt

Advanced Usages

Parsing options.

By default, when your glob pattern is parsed, DotNet.Glob will only allow literals which are valid for path / directory names. These are:

  1. Any Letter (A-Z, a-z) or Digit
  2. ., , !, #, -, ;, =, @, ~, _, :

This is optimised for matching against paths / directory strings. However, introduced in version 1.6.4, you can override this behaviour so that you can include arbitrary characters in your literals. For example, here is a pattern that matches the literal "Stuff:

    // Overide the default options globally for all matche:
    GlobParseOptions.Default.Parsing.AllowInvalidPathCharacters = true;
    DotNet.Globbing.Glob.Parse("\"Stuff*").IsMatch("\"Stuff"); // true;    

You can also just set these options on a per glob pattern basis:

    GlobOptions options = new GlobOptions();
    options.Parsing.AllowInvalidPathCharacters = allowInvalidPathCharcters;
    DotNet.Globbing.Glob.Parse("\"Stuff*", globParseOptions).IsMatch("\"Stuff"); // true; 

Case Sensitivity (Available as of version >= 2.0.0)

By default, evaluation is case-sensitive unless you specify otherwise.

    GlobOptions options = new GlobOptions();
    options.Evaluation.CaseInsensitive = true;
    DotNet.Globbing.Glob.Parse("foo*", globParseOptions).IsMatch("FOo"); // true; 

Setting CaseInsensitive has an impact on:

  • Letter Ranges. Any letter range (i.e '[A-Z]') will now match both lower or upper case characters.
  • Character Lists. Any character list (i.e '[ABC]') will now match both lower or upper case characters.
  • Literals. Any literal (i.e 'foo') will now match both lower or upper case characters i.e FoO will match foO etc.

Match Generation

Given a glob, you can generate random matches, or non matches, for that glob. For example, given the glob pattern /f?o/bar/**/*.txt you could generate matching strings like /foo/bar/ajawd/awdaw/adw-ad.txt or random non matching strings.

  var dotnetGlob = Glob.Parse(pattern);
  var generator = new GlobMatchStringGenerator(dotnetGlob.Tokens);

  for (int i = 0; i < 10; i++)
  {
          var testString = generator.GenerateRandomMatch();
          var result = dotnetGlob.IsMatch(testString);
          // result is always true.

          // generate a non match.
          testString = generator.GenerateRandomNonMatch();
          var result = dotnetGlob.IsMatch(testString);
           // result is always false.
  }

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 is compatible.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • .NETStandard 1.1

NuGet packages (40)

Showing the top 5 NuGet packages that depend on DotNet.Glob:

Package Downloads
Dazinator.Extensions.FileProviders

Dazinator.Extensions.FileProviders

Casbin.NET

Casbin.NET is a powerful and efficient open-source access control library for .NET (C#) projects. It provides support for enforcing authorization based on various access control models.

Carbon.Feature.Web

Feature to support development and runtime of Web services.

OpenMod.Core

Core service implementations for OpenMod

Traffk.StorageProviders.Common

Common set of functionality, base classes, and add-ons for Traffk.StorageProvider.Interfaces

GitHub repositories (23)

Showing the top 5 popular GitHub repositories that depend on DotNet.Glob:

Repository Stars
jellyfin/jellyfin
The Free Software Media System
Kareadita/Kavita
Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
rnwood/smtp4dev
smtp4dev - the fake smtp email server for development and testing
microsoft/kiota
OpenAPI based HTTP Client code generator
stryker-mutator/stryker-net
Mutation testing for .NET core and .NET framework!
Version Downloads Last updated
3.2.0-alpha.36 22,802 9/27/2021
3.2.0-alpha.33 263 3/5/2021
3.2.0-alpha.32 209 3/5/2021
3.2.0-alpha.31 206 3/5/2021
3.2.0-alpha.30 225 3/5/2021
3.2.0-alpha.29 310 12/26/2020
3.2.0-alpha.26 270 12/26/2020
3.2.0-alpha.25 273 12/26/2020
3.2.0-alpha.22 299 11/27/2020
3.2.0-alpha.21 1,187 8/21/2020
3.1.3 1,879,596 9/27/2021
3.1.2 423,552 12/26/2020
3.1.0 6,110,419 8/21/2020
3.1.0-issue-75.1 362 5/24/2020
3.1.0-alpha0009 69,723 8/3/2019
3.1.0-alpha0004 3,379 3/24/2019
3.1.0-alpha.51 297 8/21/2020
3.1.0-alpha.49 317 5/24/2020
3.1.0-alpha.47 313 3/5/2020
3.0.9 214,223 3/5/2020
3.0.9-beta.1 301 3/5/2020
3.0.8-beta0001 1,089 2/22/2020
3.0.5 258,989 4/2/2019
3.0.2-beta0001 1,364 4/2/2019
3.0.1 37,465 3/24/2019
3.0.1-beta0001 1,292 3/24/2019
3.0.0-alpha0052 1,338 3/24/2019
3.0.0-alpha0048 1,334 3/24/2019
3.0.0-alpha0045 1,424 2/11/2019
3.0.0-alpha0043 1,658 12/15/2018
3.0.0-alpha0041 2,758 9/12/2018
2.2.0-alpha0002 1,531 9/11/2018
2.2.0-alpha0001 1,531 8/24/2018
2.1.4 3,932 4/2/2019
2.1.3 1,786 3/24/2019
2.1.3-beta0001 1,419 3/24/2019
2.1.1 266,523 9/12/2018
2.1.0 3,816 8/24/2018
2.1.0-escaping0001 1,592 8/15/2018
2.1.0-alpha0034 1,560 8/24/2018
2.1.0-alpha0033 1,559 8/24/2018
2.1.0-alpha0022 1,684 8/10/2018
2.1.0-alpha0020 1,889 4/27/2018
2.0.3 126,560 4/27/2018
2.0.3-beta0001 2,069 4/27/2018
2.0.2 1,682 4/27/2018
2.0.1 100,890 3/27/2018
2.0.0 7,684 3/20/2018
2.0.0-alpha0139 1,450 3/11/2018
2.0.0-alpha0137 1,483 3/11/2018
2.0.0-alpha0130 1,464 3/11/2018
2.0.0-alpha0128 1,443 3/11/2018
2.0.0-alpha0127 1,476 3/11/2018
2.0.0-alpha0126 1,426 3/11/2018
2.0.0-alpha0125 1,419 3/11/2018
2.0.0-alpha0124 1,428 3/11/2018
2.0.0-alpha0123 1,445 3/11/2018
2.0.0-alpha0122 1,454 3/11/2018
2.0.0-alpha0121 1,410 3/11/2018
2.0.0-alpha0116 1,719 12/22/2017
2.0.0-alpha0115 1,441 12/22/2017
1.7.0-unstable0022 1,606 9/6/2017
1.7.0-unstable0018 1,370 8/27/2017
1.7.0-unstable0017 1,378 8/27/2017
1.7.0-unstable0013 1,380 7/12/2017
1.7.0-unstable0012 1,366 7/12/2017
1.7.0-unstable0009 1,467 6/30/2017
1.7.0-unstable0004 1,391 6/6/2017
1.7.0-unstable0001 1,418 5/18/2017
1.7.0-alpha0033 1,516 10/2/2017
1.6.9 9,790 10/2/2017
1.6.6 2,124 9/6/2017
1.6.5 1,777 8/27/2017
1.6.4 91,440 7/12/2017
1.6.3 1,745 6/30/2017
1.6.1 1,670 6/6/2017
1.6.0 3,138 5/18/2017
1.6.0-unstable0003 1,374 5/18/2017
1.6.0-unstable0002 1,386 5/12/2017
1.6.0-unstable0001 1,614 5/5/2017
1.5.0 1,597 5/5/2017
1.5.0-unstable0028 1,372 5/5/2017
1.5.0-unstable0027 1,421 5/5/2017
1.5.0-unstable0014 1,374 3/6/2017
1.5.0-unstable0013 1,366 3/6/2017
1.5.0-unstable0011 1,473 1/7/2017
1.5.0-unstable0010 1,422 1/5/2017
1.5.0-unstable0007 1,443 1/5/2017
1.5.0-unstable0006 1,473 12/19/2016
1.5.0-unstable0005 1,378 12/17/2016
1.5.0-unstable0001 1,429 12/15/2016
1.4.2 13,088 1/5/2017
1.4.1 10,369 12/17/2016
1.4.0 1,597 12/15/2016
1.4.0-unstable0004 1,443 12/15/2016
1.4.0-unstable0002 1,369 12/15/2016
1.4.0-unstable0001 1,467 12/14/2016
1.3.0 1,630 12/14/2016
1.3.0-unstable0021 1,382 12/12/2016
1.3.0-unstable0019 1,451 12/12/2016
1.3.0-unstable0018 1,443 12/12/2016
1.3.0-unstable0017 1,411 12/11/2016
1.3.0-unstable0016 1,444 12/11/2016
1.3.0-unstable0015 1,471 12/11/2016
1.3.0-unstable0014 1,481 12/10/2016
1.3.0-unstable0010 1,530 12/10/2016
1.3.0-unstable0008 1,474 12/10/2016
1.3.0-unstable0004 1,414 12/9/2016
1.3.0-unstable0002 1,448 12/9/2016
1.2.2 1,669 12/10/2016
1.2.1 1,660 12/9/2016
1.2.0-unstable0001 1,412 12/9/2016
1.1.0 1,753 12/9/2016
1.1.0-unstable0008 1,471 12/9/2016
1.1.0-unstable0005 1,448 12/7/2016
1.1.0-unstable0002 1,363 12/7/2016
1.1.0-unstable0001 1,396 12/7/2016
1.0.1 1,715 12/7/2016
1.0.0 1,654 12/7/2016
0.1.0 2,174 12/7/2016
0.1.0-unstable0012 1,452 12/7/2016

New features and fixes. See README in Github Repo.