GlobRegex 1.0.1

dotnet add package GlobRegex --version 1.0.1                
NuGet\Install-Package GlobRegex -Version 1.0.1                
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="GlobRegex" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GlobRegex --version 1.0.1                
#r "nuget: GlobRegex, 1.0.1"                
#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 GlobRegex as a Cake Addin
#addin nuget:?package=GlobRegex&version=1.0.1

// Install GlobRegex as a Cake Tool
#tool nuget:?package=GlobRegex&version=1.0.1                

GlobRegex  License

A simple fully tested Glob to Regex conversion library for .NET with no external dependencies targeting netstadard2.0

Build and test NuGet NuGet Downloads

Glob is a pattern that defines a set of file system entries using wildcards. GlobRegex allows you to convert a glob into a regular expression pattern splitting the glob into a base directory from which a recursive traversal can be started, and a stem that can be used to match a relative path.

Usage

var glob = GlobConvert.ToRegexPattern("../usr/doc?/**/*.txt", GlobRegexOptions.MatchFullString);
var regex = new Regex(glob.StemRegexPattern, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Directory.EnumerateFiles(glob.BasePath, "*", new EnumerationOptions {RecurseSubdirectories = true})
    .Select(path => Path.GetRelativePath(glob.BasePath, path))
    .Where(path => regex.IsMatch(path))
    .ForEach(Console.WriteLine);

Patterns

The following patterns are supported:

Pattern Description Example
? Any single character except the directory separator 202305??.log
* Zero or more of any characters except the directory separator src/*.md
**/ Zero or more path segments ending with the directory separator **/bin/
** Equivalent of **/*, only valid at the beginning of the segment, if it occurs not at the beginning of the segment it is interpreted as consecutive * **, **.cs
*. Trailing dot changes the behavior of the wildcards (?, *, **) of the last segment of the path to not include a dot, i.e. allows to match file system entries without extension. If there are no wildcards in the last segment, the trailing dot is treated as a regular character test/*., split/x?a.

Both / and \ are treated as directory separator characters. So **/* is the same as **\*. Consecutive * after ** (and * if not at the beginning of the segment) are ignored. So ***/abc*** is the same as **/abc*. Escaping of wildcard characters is not supported.

The passed glob is not normalized, in particular ./ and ../, consecutive directory separators like // or \\, etc. processed literally. ./ and ../ in normal use are expected to appear only in the BasePath and can be normalized afterwards. In the usage example above Path.GetRelativePath method resolve paths by calling the GetFullPath normalization method before calculating the difference.

Reproducible builds

GlobRegex nuget package is built using ReproducibleBuilds with the SourceLink. Reproducible builds give confidence by allowing to validate that the package has actually been built using public sources. To be able to reproduce a build, you need the source files, the referenced DLLs, the compiler version, and the compiler options (language version, defines, nullables, etc.). All this information is available using Nuget Package Explorer. Or you can use dotnet-validate tool to validate the package.

Author

Copyright (c) Dmitriy dscheg Titarenko 2023

GlobRegex is distributed under BSD 3-Clause License

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework 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 tizen40 was computed.  tizen60 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.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 2,009 5/26/2023
1.0.0 477 5/24/2023
0.9.1 439 5/22/2023
0.9.0 153 5/22/2023