.NET Regular Expressions

Updated: 03 April 2024

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);