...

/

Using Regular Expressions in C# with Groups

Using Regular Expressions in C# with Groups

Learn how to use groups with regular expressions.

Groups

Groups are a way of subdividing the match that regular expressions find. We specify groups with parentheses in regular expressions.

For example, we have the following input string:

The quick brown fox jumps over the lazy dog.

To match all the words in this string, we use the following regular expression:

Press + to interact
using System.Text.RegularExpressions;
class HelloWorld
{
static void Main()
{
string text = "The quick brown fox jumped over the lazy dog.";
Match match = Regex.Match(text, "\\w+");
System.Console.WriteLine(match.Groups[0]);
}
}

The regular expression \w+ matches the first word ...