C# Regex groups

public void TestRegex()
{
    //sample version regex
    string regexExpression = @"^(?<Major>\d+)\.(?<Minor>\d+)\.(?<Build>\d+)\.(?<Revision>\d+)$";
    string text = "1.0.0.0";
    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]);
        }
    } 
}

Comments

Popular posts from this blog

Tibco Rendezvous (tibrv) C# .Net example

Parse XML to dynamic object in C#