DotNet.Glob 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNet.Glob --version 2.0.0
                    
NuGet\Install-Package DotNet.Glob -Version 2.0.0
                    
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.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNet.Glob" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DotNet.Glob" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNet.Glob --version 2.0.0
                    
#r "nuget: DotNet.Glob, 2.0.0"
                    
#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.
#addin nuget:?package=DotNet.Glob&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DotNet.Glob&version=2.0.0
                    
Install as a Cake Tool

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 (45)

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.

Microsoft.OpenApi.Kiota.Builder

The core engine behind the OpenAPI based client generator.

Carbon.Feature.Web

Feature to support development and runtime of Web services.

OpenMod.Core

Core service implementations for OpenMod

GitHub repositories (24)

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

Repository Stars
jellyfin/jellyfin
The Free Software Media System - Server Backend & API
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!
casbin/Casbin.NET
An authorization library that supports access control models like ACL, RBAC, ABAC in .NET (C#)
hvanbakel/CsprojToVs2017
Tooling for converting pre 2017 project to the new Visual Studio 2017 format.
security-code-scan/security-code-scan
Vulnerability Patterns Detector for C# and VB.NET
meziantou/Meziantou.Framework
xoofx/dotnet-releaser
Easily build, run tests and coverage, cross-compile, package and publish your .NET library or application to NuGet and GitHub.
orlikoski/CyLR
CyLR - Live Response Collection Tool
nkdAgility/azure-devops-migration-tools
Azure DevOps Migration Tools allow you to migrate Teams, Backlogs, Work Items, Tasks, Test Cases, and Plans & Suits from one Project to another in Azure DevOps / TFS both within the same Organisation, and between Organisations.
microsoft/component-detection
Scans your project to determine what components you use
jinek/Consolonia
A cross-platform UI framework for .NET.
U-C-S/Hurl
Choose the browser on the click of a link
openmod/openmod
OpenMod .NET Plugin Framework
realvizu/NsDepCop
NsDepCop is a static code analysis tool that enforces namespace and assembly dependency rules in C# projects.
ShokoAnime/Shokofin
Repository for Shokofin, a plugin that brings Shoko to Jellyfin.
opentap/opentap
This is the code for the base OpenTAP package. See https://opentap.io. This includes the OpenTap.dll (base classes and sequencer), OpenTap.Package.dll (package manager), tap.exe (CLI) and OpenTap.Plugins.BasicSteps.dll (some basic TestSteps)
ESPresense/ESPresense-companion
HA Add-on / Docker container that solves indoor positions with mqtt data received from multiple ESPresense nodes
Version Downloads Last Updated
3.2.0-alpha.36 38,811 9/27/2021
3.2.0-alpha.33 330 3/5/2021
3.2.0-alpha.32 278 3/5/2021
3.2.0-alpha.31 281 3/5/2021
3.2.0-alpha.30 303 3/5/2021
3.2.0-alpha.29 384 12/26/2020
3.2.0-alpha.26 340 12/26/2020
3.2.0-alpha.25 341 12/26/2020
3.2.0-alpha.22 370 11/27/2020
3.2.0-alpha.21 1,262 8/21/2020
3.1.3 2,730,946 9/27/2021
3.1.2 456,250 12/26/2020
3.1.0 7,191,820 8/21/2020
3.1.0-issue-75.1 440 5/24/2020
3.1.0-alpha0009 69,918 8/3/2019
3.1.0-alpha0004 3,466 3/24/2019
3.1.0-alpha.51 376 8/21/2020
3.1.0-alpha.49 391 5/24/2020
3.1.0-alpha.47 391 3/5/2020
3.0.9 252,229 3/5/2020
3.0.9-beta.1 313 3/5/2020
3.0.8-beta0001 1,164 2/22/2020
3.0.5 268,657 4/2/2019
3.0.2-beta0001 1,451 4/2/2019
3.0.1 40,059 3/24/2019
3.0.1-beta0001 1,381 3/24/2019
3.0.0-alpha0052 1,437 3/24/2019
3.0.0-alpha0048 1,426 3/24/2019
3.0.0-alpha0045 1,508 2/11/2019
3.0.0-alpha0043 1,762 12/15/2018
3.0.0-alpha0041 2,875 9/12/2018
2.2.0-alpha0002 1,645 9/11/2018
2.2.0-alpha0001 1,643 8/24/2018
2.1.4 4,108 4/2/2019
2.1.3 1,900 3/24/2019
2.1.3-beta0001 1,504 3/24/2019
2.1.1 317,891 9/12/2018
2.1.0 3,957 8/24/2018
2.1.0-escaping0001 1,720 8/15/2018
2.1.0-alpha0034 1,685 8/24/2018
2.1.0-alpha0033 1,673 8/24/2018
2.1.0-alpha0022 1,809 8/10/2018
2.1.0-alpha0020 2,163 4/27/2018
2.0.3 135,670 4/27/2018
2.0.3-beta0001 2,342 4/27/2018
2.0.2 1,965 4/27/2018
2.0.1 101,219 3/27/2018
2.0.0 8,037 3/20/2018
2.0.0-alpha0139 1,731 3/11/2018
2.0.0-alpha0137 1,760 3/11/2018
2.0.0-alpha0130 1,740 3/11/2018
2.0.0-alpha0128 1,716 3/11/2018
2.0.0-alpha0127 1,748 3/11/2018
2.0.0-alpha0126 1,700 3/11/2018
2.0.0-alpha0125 1,693 3/11/2018
2.0.0-alpha0124 1,704 3/11/2018
2.0.0-alpha0123 1,716 3/11/2018
2.0.0-alpha0122 1,726 3/11/2018
2.0.0-alpha0121 1,686 3/11/2018
2.0.0-alpha0116 2,001 12/22/2017
2.0.0-alpha0115 1,719 12/22/2017
1.7.0-unstable0022 1,804 9/6/2017
1.7.0-unstable0018 1,567 8/27/2017
1.7.0-unstable0017 1,572 8/27/2017
1.7.0-unstable0013 1,574 7/12/2017
1.7.0-unstable0012 1,572 7/12/2017
1.7.0-unstable0009 1,659 6/30/2017
1.7.0-unstable0004 1,584 6/6/2017
1.7.0-unstable0001 1,609 5/18/2017
1.7.0-alpha0033 1,713 10/2/2017
1.6.9 10,024 10/2/2017
1.6.6 2,333 9/6/2017
1.6.5 2,072 8/27/2017
1.6.4 91,852 7/12/2017
1.6.3 1,950 6/30/2017
1.6.1 1,872 6/6/2017
1.6.0 3,346 5/18/2017
1.6.0-unstable0003 1,567 5/18/2017
1.6.0-unstable0002 1,581 5/12/2017
1.6.0-unstable0001 1,807 5/5/2017
1.5.0 1,796 5/5/2017
1.5.0-unstable0028 1,587 5/5/2017
1.5.0-unstable0027 1,614 5/5/2017
1.5.0-unstable0014 1,567 3/6/2017
1.5.0-unstable0013 1,560 3/6/2017
1.5.0-unstable0011 1,669 1/7/2017
1.5.0-unstable0010 1,626 1/5/2017
1.5.0-unstable0007 1,641 1/5/2017
1.5.0-unstable0006 1,669 12/19/2016
1.5.0-unstable0005 1,578 12/17/2016
1.5.0-unstable0001 1,626 12/15/2016
1.4.2 23,586 1/5/2017
1.4.1 10,592 12/17/2016
1.4.0 1,807 12/15/2016
1.4.0-unstable0004 1,641 12/15/2016
1.4.0-unstable0002 1,564 12/15/2016
1.4.0-unstable0001 1,685 12/14/2016
1.3.0 1,838 12/14/2016
1.3.0-unstable0021 1,579 12/12/2016
1.3.0-unstable0019 1,645 12/12/2016
1.3.0-unstable0018 1,637 12/12/2016
1.3.0-unstable0017 1,607 12/11/2016
1.3.0-unstable0016 1,640 12/11/2016
1.3.0-unstable0015 1,665 12/11/2016
1.3.0-unstable0014 1,691 12/10/2016
1.3.0-unstable0010 1,725 12/10/2016
1.3.0-unstable0008 1,668 12/10/2016
1.3.0-unstable0004 1,608 12/9/2016
1.3.0-unstable0002 1,642 12/9/2016
1.2.2 1,875 12/10/2016
1.2.1 1,868 12/9/2016
1.2.0-unstable0001 1,608 12/9/2016
1.1.0 1,955 12/9/2016
1.1.0-unstable0008 1,682 12/9/2016
1.1.0-unstable0005 1,641 12/7/2016
1.1.0-unstable0002 1,557 12/7/2016
1.1.0-unstable0001 1,589 12/7/2016
1.0.1 1,988 12/7/2016
1.0.0 1,856 12/7/2016
0.1.0 2,486 12/7/2016
0.1.0-unstable0012 1,644 12/7/2016

New features and fixes. See README in Github Repo.