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:
The regular expression \w+ matches the first word The. However, what if we want to match only the first three words? We can use a group for this:
(\w+) (\w+) (\w+)
This regular expression matches “The quick brown.”