How do I use regular expressions in C#

C#, regular expressions, Regex, pattern matching
This content provides a brief overview of how to use regular expressions in C# for pattern matching.
        
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string input = "Hello, my email is example@mail.com.";
        string pattern = @"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b";

        Match match = Regex.Match(input, pattern);
        if (match.Success)
        {
            Console.WriteLine("Valid email found: " + match.Value);
        }
        else
        {
            Console.WriteLine("No valid email found.");
        }
    }
}
        
    

C# regular expressions Regex pattern matching