C# Regex groups

public void TestRegex()
    //sample version regex
    string regexExpression = @"^(?<Major>\d+)\.(?<Minor>\d+)\.(?<Build>\d+)\.(?<Revision>\d+)$";
    string text = "";
    Regex regex = new Regex(regexExpression);
    //case insensitive
    //Regex regex = new Regex(regextTextBox.Text, RegexOptions.IgnoreCase);
    Match match = regex.Match(text);
    if (match.Success)
        foreach (string groupName in regex.GetGroupNames())
            Console.WriteLine("{0}={1}", groupName, match.Groups[groupName]);


Popular posts from this blog

Parse XML to dynamic object in C#

Parse XML to object model in C# using XSD utility