Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

Capture::Value Property

Gets the captured substring from the input string.

Namespace:  System.Text.RegularExpressions
Assembly:  System (in System.dll)
public:
property String^ Value {
	String^ get ();
}

Property Value

Type: System::String
The substring that is captured by the match.

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 Capture::Value property displays the result string for each capture.

No code example is currently available or this language may not be supported.

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.

Pattern

Description

(\w+)

Match one or more word characters. This is the second capturing group.

[\s.])

Match a white-space character or period (".").

((\w+)[\s.])

Match one or more word characters followed by a white-space character or period ("."). This is the first capturing group.

((\w+)[\s.])+

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.

No code example is currently available or this language may not be supported.

The regular expression pattern is defined as shown in the following table:

Pattern

Description

^

Begin the match at the beginning of the string.

([a-z]+)

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.

(\d+)?

Match zero or one occurrence of one or more decimal digits. This is the second capturing group.

\.

Match a literal period character.

([a-z]+

Match one or more occurrences of any character from a to z. The comparison is case-insensitive.

(\d)*

Match zero or more decimal digits. A single matched digit is the fourth capturing group.

([a-z]+(\d)*)

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 Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.