Skip to content

About

A creative way to Create regular expression patterns using readable API.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Repository files navigation

Masterly.FluentRegex: readable, provable regular expressions for .NET

Masterly.FluentRegex

A fluent, immutable API for building .NET regular expressions, plus the tools to understand, test, secure and ship them.

📖 Read the documentation  ·  Quick Start  ·  Examples  ·  API Reference  ·  Playground

Docs Nuget Nuget GitHub last commit GitHub Build CodeQL Analysis Publish to NuGet

All documentation lives on the documentation site. It covers every feature with run-verified examples, the full API reference and the upgrade guide. This README is only a short introduction.

Install

dotnet add package Masterly.FluentRegex

The package includes the source generator and analyzers. It targets .NET 10, .NET 8 and .NET Standard 2.1. See Installation for the companion packages and the command-line tool.

In 30 seconds

using Masterly.FluentRegex;

Pattern pattern = Pattern.With
    .StartOfLine
    .Digit.Repeat.OneOrMore
    .Literal("-")
    .Word.Repeat.Times(3, 5)
    .EndOfLine;

bool isMatch = pattern.IsMatch("123-abc");   // true
bool noMatch = pattern.IsMatch("abc-123");   // false
string regex = pattern.ToString();           // ^\d+-\w{3,5}$

Continue with the Quick Start, or try it in the browser in the Playground.

What it can do

Build A readable fluent builder with automatic escaping, groups, lookaround, composition, semantic rules such as Luhn checks, and a library of common patterns
Match Matching, replacing and splitting, typed extraction, typed templates, streaming, PII redaction and Unicode scripts
Prove Equivalence proofs with counterexamples, language facts, a verified optimizer and ReDoS analysis
Test Explain and debug, match tracing, regex coverage, test data, property testing, a backtracking profiler and railroad diagrams
Ship Regex to fluent code, learning from examples, AI drafting, JavaScript and JSON Schema export, SQL regex dialects and SQL LIKE
Integrate EF Core, ASP.NET Core, xUnit, compile-time checks and the command-line tool

Packages

Package Adds
Masterly.FluentRegex The library, with the source generator and analyzers
Masterly.FluentRegex.EntityFrameworkCore Patterns in LINQ queries, run as the database's own regex
Masterly.FluentRegex.AspNetCore Route constraints such as {id:pattern(sku)}
Masterly.FluentRegex.Xunit [MatchingData] and [NonMatchingData] theory data
Masterly.FluentRegex.AI Drafts patterns with Claude and verifies them locally
Masterly.FluentRegex.Tool The fluentregex command-line tool

Contributing

Contributions are welcome. For major changes, please open an issue first to discuss what you would like to change.

git clone https://github.com/a7mdfre7at/Masterly.FluentRegex.git
cd Masterly.FluentRegex
dotnet test                                                # .NET 8 and .NET 10
dotnet run --project samples/Masterly.FluentRegex.Showcase  # a tour of every feature

The documentation site is in website/. Run it locally with npm ci and npm start in that folder.

License

MIT. See LICENSE.

About

A creative way to Create regular expression patterns using readable API.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages