Two-project solution demonstrating regular expressions in C#. The BasicRegexExamples project shows three regex patterns: starts-with (^Hello), ends-with (ing$), and numeric pattern matching ([0-9]+[a-zA-Z]*[0-9]+).
The RegexBenchmarks project uses BenchmarkDotNet to compare 8 different regex approaches: static Regex.Matches, new instance, compiled, cached, source-generated, and combinations thereof. Tests the pattern \b\w*(ing|ed)\b against a large text file. .NET 8, BenchmarkDotNet 0.13.12.
- .NET 8.0 SDK
For examples:
cd WorkingWithRegex.BasicRegexExamples
dotnet runFor benchmarks:
cd WorkingWithRegex.RegexBenchmarks
dotnet run -c ReleaseIf you found this useful and you want to learn more about C#, .NET, and software engineering, subscribe to the free Dev Leader Weekly newsletter:
Subscribe to Dev Leader Weekly
- All Links
- Website - Dev Leader
- YouTube - Dev Leader
- YouTube - Dev Leader Path To Tech
- YouTube - Dev Leader Podcast
- YouTube - CodeCommute
- Newsletter - Dev Leader Weekly
- LinkedIn - Nick Cosentino
- GitHub - ncosentino
- Twitter/X - Dev Leader
- Threads - Dev Leader
- Bluesky - Dev Leader
- Mastodon - Dev Leader
- Facebook - Dev Leader
- TikTok - Dev Leader
- Twitch - Dev Leader
- Stack Overflow - Nick Cosentino
Powered by BrandGhost 👻