Resharp 1.0.3
dotnet add package Resharp --version 1.0.3
NuGet\Install-Package Resharp -Version 1.0.3
<PackageReference Include="Resharp" Version="1.0.3" />
<PackageVersion Include="Resharp" Version="1.0.3" />
<PackageReference Include="Resharp" />
paket add Resharp --version 1.0.3
#r "nuget: Resharp, 1.0.3"
#:package Resharp@1.0.3
#addin nuget:?package=Resharp&version=1.0.3
#tool nuget:?package=Resharp&version=1.0.3
RE#
A high-performance, automata based regex engine with first-class support for intersection and complement operations.
RE# compiles patterns into deterministic automata. All matching is non-backtracking with guaranteed linear-time execution. RE# extends System.Text.RegularExpressions syntax with intersection (&), complement (~), and a universal wildcard (_), enabling patterns that are impossible or impractical to express with standard regex.
web playground | paper | blog post
Install
dotnet add package Resharp
Usage
// contains "cat", "dog", AND is 8-15 characters long
var re = new Resharp.Regex(@".*cat.*&.*dog.*&.{8,15}");
// instances are thread-safe, compile once and reuse
re.Matches("the cat and the dog");
Syntax extensions
RE# supports standard .NET regex syntax plus three extensions:
_ -- universal wildcard
Matches any character including newlines ([\s\S]).
& -- intersection
Both sides must match. The match is the intersection of the two languages.
_*cat_*&_*dog_* contains both "cat" and "dog"
_*cat_*&_*dog_*&_{5,30} ...and is 5-30 characters long
~(...) -- complement
Matches everything the inner pattern does not match.
~(_*\d\d_*) does not contain two consecutive digits
~(_*\n\n_*) does not contain a double newline
<details>
<summary>why _* and not .*?</summary>
we specifically included _ in the syntax so it's more intuitive to use with complement.
.* does not match newlines, so it does not mean "any string" (rather "any one line").
</details>
Combining operators
F.*&~(_*Finn) starts with 'F', does not end with "Finn"
~(_*\d\d_*)&[a-zA-Z\d]{8,} 8+ alphanumeric, no consecutive digits
Performance
RE# uses several optimizations: start-set inference, literal prefix scanning, and optional full DFA precompilation. RE# shares many optimizations with .NET's (and RegexOptions.NonBacktracking even shares some RE# techniques and strengths that many do not know of!) but RE# is designed from the ground up and returns a different kind of matches (leftmost-longest).
RE# particularly excels with large patterns and will often outperform .NET's regex engine (and all others) for complex patterns, especially those with a large set of alternatives, loops or using context-awareness - RE# supports lookarounds, which is unique among automata engines.
To illustrate, here is a little comparison of RE# with .NET's most used compiled and source-generated regex engines on these patterns, you can also find wider comparisons in the paper:
On curated benchmarks from rebar (AMD Ryzen 7 5800X, .NET 10.0):
| Pattern | RE# | .NET Compiled | .NET SourceGenerated | Speedup |
|---|---|---|---|---|
| date extraction | 1,737 us | 273,822 us | 318,070 us | 158x |
| dictionary search | 105 us | 45,832 us | 26,410 us | 252x |
And on some extensions we added ourselves:
| Pattern | RE# | .NET Compiled | .NET SourceGenerated | Speedup |
|---|---|---|---|---|
| dictionary, case-insensitive | 576 us | 29,368 us | 21,146 us | 37x |
| unicode dictionary | 336 us | 62,053 us | 38,613 us | 115x |
| unicode dictionary, case-insensitive | 321 us | 484,135 us | 537,814 us | 1,508x |
| dictionary + context window | 621 us | 48,893 us | 55,383 us | 79x |
| dictionary + context window, unicode | 692 us | 24,105,091 us | 34,706,982 us | 34,833x |
<details> <summary>Where is RegexOptions.NonBacktracking?</summary>
Conveniently left out for shock effect :^). NonBacktracking is actually much closer to RE#, but still behind. See the paper for a fairer comparison.
</details>
For critical paths, you can use ValueMatches for memory-pooled matching and ResharpOptions.HighThroughputDefaults for more aggressive optimization.
var re = new Resharp.Regex("pattern", ResharpOptions.HighThroughputDefaults);
using var slices = re.ValueMatches(chars);
foreach (var s in slices)
Console.WriteLine($"match at {s.Index}..{s.Index + s.Length}");
Documentation
- Syntax reference -- full pattern syntax including
&,~,_ - API reference -- all public types and methods
Examples
Runnable scripts in examples/:
| File | Description |
|---|---|
| basic-syntax.fsx | wildcards, intersection, complement |
| paragraph.fsx | paragraph extraction with complement and intersection |
| validation.fsx | date, IP, password validation with intersection |
| replace.fsx | string and function-based replacement |
| lookaround.fsx | lookahead, lookbehind, combined with intersection |
| high-throughput.fsx | zero-allocation matching for large inputs |
| Basic.cs | C# usage |
Have fun!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
-
net10.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.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.3 | 496 | 3/12/2026 |
| 1.0.2 | 660 | 3/1/2026 |
| 1.0.1 | 130 | 2/24/2026 |
| 1.0.0 | 109 | 2/22/2026 |
| 0.2.2-library | 201 | 9/29/2025 |
| 0.2.1 | 607 | 9/27/2025 |
| 0.2.1-library | 121 | 9/27/2025 |
| 0.1.34 | 628 | 2/22/2025 |
| 0.1.33 | 340 | 11/30/2024 |
| 0.1.25 | 774 | 6/27/2024 |
| 0.1.24 | 183 | 6/27/2024 |
| 0.1.17 | 222 | 6/8/2024 |
| 0.0.1-library | 196 | 12/11/2024 |