Masterly.FluentRegex
1.0.0
See the version list below for details.
dotnet add package Masterly.FluentRegex --version 1.0.0
NuGet\Install-Package Masterly.FluentRegex -Version 1.0.0
<PackageReference Include="Masterly.FluentRegex" Version="1.0.0" />
paket add Masterly.FluentRegex --version 1.0.0
#r "nuget: Masterly.FluentRegex, 1.0.0"
// Install Masterly.FluentRegex as a Cake Addin #addin nuget:?package=Masterly.FluentRegex&version=1.0.0 // Install Masterly.FluentRegex as a Cake Tool #tool nuget:?package=Masterly.FluentRegex&version=1.0.0
Masterly.FluentRegex
A creative way to Create regular expression patterns using readable API
Give a Star! ⭐
If you like or are using this project please give it a star. Thanks!
Introduction
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. - Jamie Zawinski
Does that make this a 3rd problem?
Regular expressions can be extremely useful in the right circumstances, but they can also be terriblly complicated to understand. Consider this regular expression for parsing email addresses based on the RFC 5322 standard:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
| "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])*")
@ (?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
| \[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])+)
\])
What human can possibly read and understand that?
In an effort to create a more readable method of writing regular expressions in .NET, I've created FluentRegex.
Examples
Let's use a simpler email regular expression to demonstrate some of the library's capabilities.
Normally, we'd write the regular expression something like this:
string regex = @"^[a-zA-Z\d\.-_]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,4}$";
With FluentRegex, we can express it like this:
Pattern p = Pattern.With
.StartOfLine
.Set(Pattern.With.Letter.Digit.Literal(".-_")).Repeat.OneOrMore
.Literal("@")
.Set(Pattern.With.Letter.Digit.Literal(".-")).Repeat.OneOrMore
.Literal(".")
.Set(Pattern.With.Letter).Repeat.Times(2, 4)
.EndOfLine;
For more samples, please see tests in unit test project Here
License
MIT
Free Software, Hell Yeah!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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 is compatible. 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 is compatible. 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. |
-
.NETCoreApp 2.0
- Masterly.AssembliesScanner (>= 1.0.0)
-
.NETFramework 4.6.2
- Masterly.AssembliesScanner (>= 1.0.0)
-
.NETStandard 2.0
- Masterly.AssembliesScanner (>= 1.0.0)
-
net5.0
- Masterly.AssembliesScanner (>= 1.0.0)
- Masterly.Extensions.Core (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initail release