Skip to content

ndcorder/regexcraft

Repository files navigation

RegexCraft

RegexCraft is a fluent C# API for building regular expressions with full IntelliSense-friendly method chaining.

Installation

dotnet add package RegexCraft

Quick Start

using RegexCraft;

var pattern = Pattern.StartOfLine
    .Exactly(3).Digits
    .Then("-")
    .Exactly(4).Digits
    .EndOfLine;

var regexText = pattern.Build(); // ^\d{3}\-\d{4}$
var isMatch = pattern.Test("555-1234"); // true

Fluent API Examples

var emailLike = Pattern.StartOfLine
    .OneOrMore.WordChars
    .Then("@")
    .OneOrMore.WordChars
    .Then(".")
    .Between(2, 6).Letters
    .EndOfLine;
var optionalPlural = Pattern.Then("item").Optional.Then("s");

Pre-built Patterns

Patterns.Email.Test("user@example.com");
Patterns.Url.Test("https://example.com");
Patterns.IpV4.Test("192.168.1.1");
Patterns.Phone.Test("555-1234");
Patterns.Guid.Test("550e8400-e29b-41d4-a716-446655440000");

Explain Feature

var explanation = Pattern.StartOfLine
    .Exactly(3).Digits
    .Then("-")
    .Exactly(4).Digits
    .EndOfLine
    .Explain();

// Start of line, exactly 3 digits, literal '-', exactly 4 digits, end of line

GeneratedRegex Feature

var generated = Pattern.StartOfLine
    .OneOrMore.Digits
    .EndOfLine
    .ToGeneratedRegex("DigitsOnly");

// [GeneratedRegex(@"^\d+$")]
// private static partial Regex DigitsOnly();

Quality Gates

RegexCraft includes strict quality automation:

  • Coverage gate: line coverage must be at least 95% and branch coverage at least 85%.
  • Mutation gate: Stryker mutation score thresholds are high: 95, low: 90, break: 85 (see stryker-config.json).

Run everything locally:

./scripts/quality-gates.sh

Or run steps manually:

dotnet test RegexCraft.sln /p:CollectCoverage=true /p:Threshold=95%2c85 /p:ThresholdType=line%2cbranch /p:ThresholdStat=total
dotnet tool restore
dotnet stryker --config-file stryker-config.json

CI workflow: .github/workflows/quality-gates.yml.

API Compatibility Baseline

Public API compatibility is tracked via:

  • api/PublicApi.Shipped.txt
  • tests/RegexCraft.Tests/ApiCompatibilityBaselineTests.cs

If public APIs intentionally change, update the baseline file and record the change in CHANGELOG.md.

Benchmarks

Run BenchmarkDotNet benchmarks locally:

./scripts/run-benchmarks.sh

Release & NuGet Publish

  • Version and package metadata live in src/RegexCraft/RegexCraft.csproj.
  • Changelog is tracked in CHANGELOG.md.
  • Tag a release with v* (for example v1.0.1) to trigger:
    • .github/workflows/publish-nuget.yml
    • build + test + dotnet pack
    • publish to NuGet using NUGET_API_KEY secret.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors