string pattern = "(?i:[A-Z])\\d";
string str = "A1 2b c2 3D";
Regex regex = new Regex(pattern);
MatchCollection matchCollection = regex.Matches(str);
foreach (var item in matchCollection)
{
Console.WriteLine(item);
}
Console.WriteLine();
pattern = "([A-Z])\\d";
str = "A1 2b c2 3D";
regex = new Regex(pattern);
matchCollection = regex.Matches(str);
foreach (var item in matchCollection)
{
Console.WriteLine(item);
}
Console.WriteLine();
pattern = "(?-i:[A-Z])\\d";
str = "A1 2b c2 3D";
regex = new Regex(pattern);
matchCollection = regex.Matches(str);
foreach (var item in matchCollection)
{
Console.WriteLine(item);
}
Console.WriteLine();
pattern = "([A-Z])\\d";
str = "A1 2b C2 3D";
regex = new Regex(pattern);
matchCollection = regex.Matches(str);
foreach (Match item in matchCollection)
{
GroupCollection groupCollection= item.Groups ;
foreach (Group subItem in groupCollection )
{
Console.WriteLine($"group{subItem .Value }");
}
}
Console.WriteLine();
pattern = "(?n:[A-Z])\\d";
str = "A1 2b C2 3D";
regex = new Regex(pattern);
matchCollection = regex.Matches(str);
foreach (Match item in matchCollection)
{
GroupCollection groupCollection = item.Groups;
foreach (Group subItem in groupCollection)
{
Console.WriteLine($"group{subItem.Value }");
}
}
Console.WriteLine();
pattern = "(?<firstGroup>[A-Z])\\d";
str = "A1 2b C2 3D";
regex = new Regex(pattern ,RegexOptions.ExplicitCapture );
matchCollection = regex.Matches(str);
foreach (Match item in matchCollection)
{
GroupCollection groupCollection = item.Groups;
foreach (Group subItem in groupCollection)
{
Console.WriteLine($"group{subItem.Value }");
}
}