.NET Regex

Updated: 05 August 2023

Find all animals names starting with an uppercase C.

string pattern = @"\b[C]\w+";
Regex rg = new Regex(pattern);

string animals = "Cat, dog, Camel, caribou";
MatchCollection matchedAnimals = rg.Matches(animals);

for (int count = 0; count < matchedAnimals.Count; count++)
Console.WriteLine(matchedAnimals[count].Value);