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. Theproperty 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.
Available since 4.5
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1