MarcusMedina.Fluent.Pattern 1.0.0

dotnet add package MarcusMedina.Fluent.Pattern --version 1.0.0
                    
NuGet\Install-Package MarcusMedina.Fluent.Pattern -Version 1.0.0
                    
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="MarcusMedina.Fluent.Pattern" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MarcusMedina.Fluent.Pattern" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MarcusMedina.Fluent.Pattern" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MarcusMedina.Fluent.Pattern --version 1.0.0
                    
#r "nuget: MarcusMedina.Fluent.Pattern, 1.0.0"
                    
#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.
#:package MarcusMedina.Fluent.Pattern@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MarcusMedina.Fluent.Pattern&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MarcusMedina.Fluent.Pattern&version=1.0.0
                    
Install as a Cake Tool

MarcusMedina.Fluent.Pattern

License: MIT .NET NuGet Tests

Fluent string pattern matching and analysis for .NET 10+

I detta fall ville jag förenkla användandet av mönsterigenkänning i C#. Strängmönster, regex, wildcards — samlat i ett Fluent API så man slipper tänka på implementationen varje gång.

SQL-inspired patterns (LIKE, IN, BETWEEN), fuzzy matching (Levenshtein, Jaro-Winkler, Jaccard), string type detection (email, URL, IP, MAC, GUID, JSON, XML and more), and utility methods (palindromes, anagrams, pangrams, phonetic keys).


Features

  • ✅ SQL-style — IsLike, IsNotLike, In, NotIn, Between
  • ✅ Shorthand — LikeContains, LikeStartsWith, LikeEndsWith
  • ✅ Fuzzy matching — LevenshteinDistance, SimilarityTo, IsSimilarTo
  • ✅ Advanced distance — DamerauLevenshtein, Hamming, Jaccard, JaroWinkler
  • ✅ String analysis — IsPalindrome, IsAnagramOf, IsPangram, LongestCommonSubstring
  • ✅ Validation — IsEmail, IsUrl, IsIpAddress
  • ✅ Type detection — DetectStringType() returns a StringType enum
  • ✅ Phonetic matching — PhoneticKey() (Soundex-inspired)
  • ✅ Zero dependencies — Pure .NET, no external packages

Installation

dotnet add package MarcusMedina.Fluent.Pattern

Requirements: .NET 10.0+, C# 14.0+


Quick Start

using MarcusMedina.Fluent.Pattern;

// SQL-like pattern matching
"hello world".IsLike("hello%");       // true
"hello world".IsNotLike("goodbye%");  // true

// Shorthand
"hello world".LikeContains("world");    // true
"hello world".LikeStartsWith("he");     // true
"hello world".LikeEndsWith("ld");       // true

// Set membership
"apple".In("apple", "banana", "cherry");      // true
"grape".NotIn("apple", "banana");             // true
"m".Between("a", "z");                        // true

// Fuzzy matching
"hello".SimilarityTo("hallo");                // ~0.8
"hello".IsSimilarTo("hallo");                 // true (default threshold 0.7)
"Kalle".LevenshteinDistance("Kålle");         // 1
"teh".DamerauLevenshteinDistance("the");      // 1
"karolin".HammingDistance("kathrin");         // 3
"hello".JaccardSimilarity("hallo");           // ~0.33
"Marcus".JaroWinklerSimilarity("Markus");     // ~0.88
"abcdef".LongestCommonSubstring("zbcdf");     // "bcd"

// Validation
"hej@example.com".IsEmail();                  // true
"https://example.com".IsUrl();                // true
"192.168.1.1".IsIpAddress();                  // true

// Type detection
"hej@example.com".DetectStringType();         // StringType.Email
"192.168.1.1".DetectStringType();             // StringType.IpAddress
"{0000-0000...}".DetectStringType();          // StringType.Guid
"42".DetectStringType();                      // StringType.Number

// String analysis
"anna".IsPalindrome();                        // true
"listen".IsAnagramOf("silent");               // true
"The quick brown fox jumps over the lazy dog".IsPangram();  // true
"hello".PhoneticKey();                        // Soundex-style key

API Overview

Pattern Matching

Method Description
IsLike(pattern) SQL LIKE with % and _ wildcards
IsNotLike(pattern) Negation of IsLike
LikeContains(value) LIKE '%value%' shorthand
LikeStartsWith(value) LIKE 'value%' shorthand
LikeEndsWith(value) LIKE '%value' shorthand
In(values) SQL IN against a list
NotIn(values) SQL NOT IN negation
Between(min, max) Range comparison

All accept optional caseSensitive parameter (default false).

Fuzzy Matching

Method Description
LevenshteinDistance(other) Edit distance (insert/delete/substitute)
DamerauLevenshteinDistance(other) Levenshtein + transpositions
HammingDistance(other) Position-by-position diff (same length only)
JaccardSimilarity(other, nGramSize) N-gram set similarity
JaroWinklerSimilarity(other) Optimized for short strings (names)
SimilarityTo(other) Normalized 0.0–1.0 (based on Levenshtein)
IsSimilarTo(other, threshold) SimilarityTo >= threshold (default 0.7)
LongestCommonSubstring(other) Longest shared substring

Validation & Detection

Method Description
IsEmail() Basic email format validation
IsUrl() http/https/ftp URL validation
IsIpAddress() IPv4 and IPv6 validation
DetectStringType() Returns StringType enum

Text Analysis

Method Description
IsPalindrome() Same forwards and backwards
IsAnagramOf(other) Same characters, different order
IsPangram() Contains all letters of the alphabet
PhoneticKey() Soundex-inspired phonetic encoding

StringType Enum

Value Detects
PlainText Unrecognized format
Email user@domain.tld
Url http://, https://, ftp://
FilePath Unix paths (/...)
WindowsPath C:\..., \\server\...
IpAddress IPv4/IPv6
SubnetMask 255.255.255.0 style
MacAddress AA:BB:CC:DD:EE:FF
Json {...} or [...]
Xml <...>
Number Integers and decimals
Guid UUIDs with/without dashes/braces
Sql SELECT, INSERT, UPDATE, etc.

Testing

dotnet test --configuration Release

Tests: 191 passed — covering pattern matching, fuzzy distance, validation, detection, string analysis, null/empty edge cases, and all StringType variants.


License

MIT — see LICENSE for details.


Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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.0 152 7/2/2026