![]() |
VOOZH | about |
dotnet add package Fluent-Regex --version 1.1.0
NuGet\Install-Package Fluent-Regex -Version 1.1.0
<PackageReference Include="Fluent-Regex" Version="1.1.0" />
<PackageVersion Include="Fluent-Regex" Version="1.1.0" />Directory.Packages.props
<PackageReference Include="Fluent-Regex" />Project file
paket add Fluent-Regex --version 1.1.0
#r "nuget: Fluent-Regex, 1.1.0"
#:package Fluent-Regex@1.1.0
#addin nuget:?package=Fluent-Regex&version=1.1.0Install as a Cake Addin
#tool nuget:?package=Fluent-Regex&version=1.1.0Install as a Cake Tool
The original fluent regular expression builder for .NET.
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.
Install-Package Fluent-Regex
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;
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package has no dependencies.
Showing the top 2 NuGet packages that depend on Fluent-Regex:
| Package | Downloads |
|---|---|
|
SaaS-Factory.AppBlueprint.Application
Application layer with CQRS commands, queries, and use cases following Clean Architecture principles |
|
|
SaaS-Factory.AppBlueprint.Infrastructure
Infrastructure library with database repositories and external services |
This package is not used by any popular GitHub repositories.