Regex in .NET 7: Faster and More Efficient

Your regex runs on every request. It also recompiles on every request - unless you do something about it. `Regex.IsMatch` handles the quick yes/no check. Named groups let you pull out values by name instead of counting parentheses like it's 1999. And `[GeneratedRegex]`, shipped in .NET 7, compiles your pattern straight to IL at build time - zero runtime overhead, and your profiler finally stops yelling at you. --- var match = Regex.Match(log, @"user=(?<email>[\w.]+@[\w.]+)\s+action=(?<action>\S+)"); Console.WriteLine(match.Groups["email"].Value); // no index guessing --- Microsoft made regex fast by default. Only took until 2022. Try it yourself (no setup required): https://lnkd.in/eg68aQiZ #dotnet #csharp #programming #regex

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories