Gets the captured substring from the input string.
Assembly: System (in System.dll)
If a call to the Regex.Match or Match.NextMatch method fails to find a match, the value of the returned Match.Value property is String.Empty. If the regular expression engine is unable to match a capturing group. the value of the returned Group.Value property is String.Empty. See the second example for an illustration.
The following example defines a regular expression that matches sentences that contain no punctuation except for a period ("."). The Match.Value property displays the result string, which consists of a matched sentence, for each match. The Group.Value property displays the result string for each capturing group; it consists of the last string captured by that capturing group. The property displays the result string for each capture.
The regular expression pattern ((\w+)[\s.])+ is defined as shown in the following table. Note that in this regular expression, a quantifier (+) is applied to the entire regular expression.
Match one or more word characters. This is the second capturing group.
Match a white-space character or period (".").
Match one or more word characters followed by a white-space character or period ("."). This is the first capturing group.
Match one or more occurrences of a word character or characters followed by a white-space character or period (".").
In this example, the input string consists of two sentences. As the output shows, the first sentence consists of only one word, so the CaptureCollection object has a single Capture object that represents the same capture as the Group object. The second sentence consists of multiple words, so the Group objects only contain information about the last matched subexpression. Group 1, which represents the first capture, contains the last word in the sentence that has a closing period. Group 2, which represents the second capture, contains the last word in the sentence. However, the Capture objects in the group's CaptureCollection object capture each subexpression match. The Capture objects in the first capturing group's collection of captures contain information about each captured word and white-space character or period. The Capture objects in the second capturing group's collection of captures contain information about each captured word.
The following example uses a regular expression pattern, ^([a-z]+)(\d+)*\.([a-z]+(\d)*)$, to match a product number that consists of two parts separated by a period. Both parts consist of alphabetic characters followed by optional numbers. Because the first input string does not match the pattern, the value of the returned System.Text.RegularExpressions.Match object's Value property is String.Empty. Similarly, when the regular expression pattern is unable to match a capturing group, the value of the corresponding Group object's Value property is String.Empty.
The regular expression pattern is defined as shown in the following table:
Begin the match at the beginning of the string.
Match one or more occurrences of any character from a to z. Because the regular expression engine is passed the RegexOptions.IgnoreCase option, this comparison is case-insensitive. This is the first capturing group.
Match zero or one occurrence of one or more decimal digits. This is the second capturing group.
Match a literal period character.
Match one or more occurrences of any character from a to z. The comparison is case-insensitive.
Match zero or more decimal digits. A single matched digit is the fourth capturing group.
Match one or more alphabetic characters from a to z followed by zero, one, or more decimal digits. This is the fourth capturing group.
Conclude the match at the end of the string.
.NET FrameworkSupported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.