Skip to content

Latest commit

 

History

History

README.md

WorkingWithRegex - Regular Expressions Examples and Benchmarks in C#

YouTube Blog Newsletter All Links LinkedIn

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.

Getting Started

Prerequisites

  • .NET 8.0 SDK

Running the Project

For examples:

cd WorkingWithRegex.BasicRegexExamples
dotnet run

For benchmarks:

cd WorkingWithRegex.RegexBenchmarks
dotnet run -c Release

Related Resources

Newsletter

If 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

Connect with Dev Leader


BrandGhost

Powered by BrandGhost 👻