How to use regular expressions in C#? - Biz Tech

How to use regular expressions in C#?

Listen
string pattern = @"\b\d{3}-\d{2}-\d{4}\b"; // matches a Social Security Number in the format XXX-XX-XXXX
string input = "My SSN is 123-45-6789";
Match match = Regex.Match(input, pattern);
if (match.Success)
{
    Console.WriteLine("SSN found: " + match.Value);
}
else
{
    Console.WriteLine("SSN not found.");
}