Rejigs 1.0.6
See the version list below for details.
dotnet add package Rejigs --version 1.0.6
NuGet\Install-Package Rejigs -Version 1.0.6
<PackageReference Include="Rejigs" Version="1.0.6" />
<PackageVersion Include="Rejigs" Version="1.0.6" />
<PackageReference Include="Rejigs" />
paket add Rejigs --version 1.0.6
#r "nuget: Rejigs, 1.0.6"
#:package Rejigs@1.0.6
#addin nuget:?package=Rejigs&version=1.0.6
#tool nuget:?package=Rejigs&version=1.0.6
Rejigs
🧩 A fluent, intuitive builder for regular expressions in C#
Rejigs makes creating complex regular expressions simple and readable by providing a fluent API that builds patterns step by step. No more cryptic regex syntax - write patterns that are easy to understand and maintain!
🚀 Getting Started
Installation
Install Rejigs via NuGet Package Manager:
dotnet add package Rejigs
Or via Package Manager Console:
Install-Package Rejigs
Basic Usage
using Rejigs;
// Simple text matching
var regex = Rejigs.Create()
.AtStart()
.Text("hello")
.AtEnd()
.Build();
Console.WriteLine(regex.IsMatch("hello")); // True
Console.WriteLine(regex.IsMatch("hello world")); // False
📖 Real-World Examples
Email Validation
var emailRegex = Rejigs.Create()
.AtStart()
.OneOrMore(r => r.AnyLetterOrDigit().Or().AnyOf(".-_")) // Local part
.Text("@")
.OneOrMore(r => r.AnyLetterOrDigit().Or().AnyOf(".-")) // Domain
.Text(".")
.Between(2, 6).AnyOf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") // TLD
.AtEnd()
.Build();
Console.WriteLine(emailRegex.IsMatch("user@example.com")); // True
Console.WriteLine(emailRegex.IsMatch("invalid-email")); // False
Phone Number Formatting
var phoneRegex = Rejigs.Create()
.AtStart()
.Optional("(")
.Exactly(3).AnyDigit() // Area code
.Optional(")")
.Optional(r => r.AnyOf(" -"))
.Exactly(3).AnyDigit() // Exchange
.Optional(r => r.AnyOf(" -"))
.Exactly(4).AnyDigit() // Number
.AtEnd()
.Build();
Console.WriteLine(phoneRegex.IsMatch("(555) 123-4567")); // True
Console.WriteLine(phoneRegex.IsMatch("555-123-4567")); // True
Console.WriteLine(phoneRegex.IsMatch("5551234567")); // True
URL Validation
var urlRegex = Rejigs.Create()
.AtStart()
.Either(
r => r.Text("http"),
r => r.Text("https")
)
.Text("://")
.OneOrMore(r => r.AnyLetterOrDigit().Or().AnyOf(".-")) // Domain
.Optional(r => r.Text(":").OneOrMore(c => c.AnyDigit())) // Port
.ZeroOrMore(r => r.Text("/").ZeroOrMore(c => c.AnyExcept(" "))) // Path
.AtEnd()
.Build();
Console.WriteLine(urlRegex.IsMatch("https://example.com/path")); // True
Console.WriteLine(urlRegex.IsMatch("http://localhost:8080")); // True
Credit Card Number
var creditCardRegex = Rejigs.Create()
.AtStart()
.Exactly(4).AnyDigit()
.Optional(r => r.AnyOf(" -"))
.Exactly(4).AnyDigit()
.Optional(r => r.AnyOf(" -"))
.Exactly(4).AnyDigit()
.Optional(r => r.AnyOf(" -"))
.Exactly(4).AnyDigit()
.AtEnd()
.Build();
Console.WriteLine(creditCardRegex.IsMatch("1234 5678 9012 3456")); // True
Console.WriteLine(creditCardRegex.IsMatch("1234-5678-9012-3456")); // True
Password Validation (Complex)
// Password must be 8-20 characters, contain uppercase, lowercase, digit, and special char
var passwordRegex = Rejigs.Create()
.AtStart()
.Grouping(r => r.ZeroOrMore(c => c.AnyCharacter()).OneOrMore(d => d.AnyInRange('A', 'Z'))) // Has uppercase
.Grouping(r => r.ZeroOrMore(c => c.AnyCharacter()).OneOrMore(d => d.AnyInRange('a', 'z'))) // Has lowercase
.Grouping(r => r.ZeroOrMore(c => c.AnyCharacter()).OneOrMore(d => d.AnyDigit())) // Has digit
.Grouping(r => r.ZeroOrMore(c => c.AnyCharacter()).OneOrMore(d => d.AnyOf("!@#$%^&*"))) // Has special
.Between(8, 20).AnyCharacter() // Length 8-20
.AtEnd()
.Build();
📚 Complete API Reference
Creating a Builder
Method | Description | Regex Equivalent |
---|---|---|
Rejigs.Create() |
Creates a new regex builder instance | - |
Anchors
Method | Description | Regex Equivalent |
---|---|---|
AtStart() |
Match at the beginning of string | ^ |
AtEnd() |
Match at the end of string | $ |
AtWordBoundary() |
Match at word boundary | \b |
NotAtWordBoundary() |
Match at non-word boundary | \B |
Character Classes
Method | Description | Regex Equivalent |
---|---|---|
AnyDigit() |
Match any digit (0-9) | \d |
AnyNonDigit() |
Match any non-digit | \D |
AnyLetterOrDigit() |
Match any word character (letters, digits, underscore) | \w |
AnyNonLetterOrDigit() |
Match any non-word character | \W |
AnySpace() |
Match any whitespace character | \s |
AnyNonSpace() |
Match any non-whitespace character | \S |
AnyCharacter() |
Match any character except newline | . |
AnyOf(string chars) |
Match any character from the specified set | [chars] |
AnyInRange(char from, char to) |
Match any character in the specified range | [from-to] |
AnyExcept(string chars) |
Match any character except those specified | [^chars] |
Text Matching
Method | Description | Regex Equivalent |
---|---|---|
Text(string text) |
Match exact text (automatically escaped) | text (escaped) |
Pattern(string pattern) |
Insert raw regex pattern | pattern (as-is) |
Quantifiers
Method | Description | Regex Equivalent |
---|---|---|
Optional(string text) |
Match text zero or one time | text? |
Optional(Func<Rejigs, Rejigs> pattern) |
Match pattern zero or one time | (pattern)? |
ZeroOrMore(Func<Rejigs, Rejigs> pattern) |
Match pattern zero or more times | (pattern)* |
OneOrMore(Func<Rejigs, Rejigs> pattern) |
Match pattern one or more times | (pattern)+ |
Exactly(int count) |
Match exactly n times | {count} |
AtLeast(int count) |
Match at least n times | {count,} |
Between(int min, int max) |
Match between min and max times | {min,max} |
Grouping and Alternation
Method | Description | Regex Equivalent |
---|---|---|
Grouping(Func<Rejigs, Rejigs> pattern) |
Create non-capturing group | (?:pattern) |
Or() |
Alternation operator | \| |
Either(params Func<Rejigs, Rejigs>[] patterns) |
Match any of the provided patterns | (?:pattern1\|pattern2\|...) |
Options
Method | Description | Regex Equivalent |
---|---|---|
IgnoreCase() |
Enable case-insensitive matching | RegexOptions.IgnoreCase |
Compiled() |
Compile regex for better performance | RegexOptions.Compiled |
Building
Method | Description | Returns |
---|---|---|
Expression |
Get the regex pattern as string | string |
Build() |
Build a Regex object with current options | Regex |
Build(RegexOptions options) |
Build a Regex object with custom options | Regex |
🔧 Performance & Options
Case-Insensitive Matching
Use IgnoreCase()
for case-insensitive matching:
var regex = Rejigs.Create()
.Text("hello")
.IgnoreCase()
.Build();
Console.WriteLine(regex.IsMatch("HELLO")); // True
Console.WriteLine(regex.IsMatch("Hello")); // True
Performance Optimization
Use Compiled()
for better performance when the regex will be used many times:
var regex = Rejigs.Create()
.AtStart()
.OneOrMore(r => r.AnyDigit())
.Compiled()
.IgnoreCase() // Can combine multiple options
.Build();
Recommended Usage Patterns
For simple, one-time use:
var regex = Rejigs.Create().Text("pattern").Build();
For case-insensitive matching:
var regex = Rejigs.Create().Text("pattern").IgnoreCase().Build();
For high-performance scenarios (repeated use):
var regex = Rejigs.Create().Pattern().Compiled().Build();
For maximum flexibility:
var regex = Rejigs.Create()
.Pattern()
.IgnoreCase()
.Compiled()
.Build();
🎯 Tips and Best Practices
- Use descriptive variable names:
var emailRegex = ...
instead ofvar regex = ...
- Break complex patterns into smaller parts: Use variables to store intermediate builders
- Add comments: Explain what each part of your regex does
- Test thoroughly: Use unit tests to verify your patterns work correctly
- Use
AtStart()
andAtEnd()
: For exact matches, always anchor your patterns
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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.