Export (0) Print
Expand All

Capture Class

Represents the results from a single successful subexpression capture.

System::Object
  System.Text.RegularExpressions::Capture
    System.Text.RegularExpressions::Group

Namespace:  System.Text.RegularExpressions
Assembly:  System (in System.dll)

[SerializableAttribute]
public ref class Capture

The Capture type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIndexThe position in the original string where the first character of the captured substring is found.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLengthGets the length of the captured substring.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsValueGets the captured substring from the input string.
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringRetrieves the captured substring from the input string by calling the Value property. (Overrides Object::ToString().)
Top

A Capture object is immutable and has no public constructor. Instances are returned through the CaptureCollection object, which is returned by the Match.Captures and Group::Captures properties. However, the Match.Captures property provides information about the same match as the Match object.

If you do not apply a quantifier to a capturing group, the Group::Captures property returns a CaptureCollection with a single Capture object that provides information about the same capture as the Group object. If you do apply a quantifier to a capturing group, the Group.Index, Group.Length, and Group.Value properties provide information only about the last captured group, whereas the Capture objects in the CaptureCollection provide information about all subexpression captures. The example provides an illustration.

The following example defines a regular expression that matches sentences that contain no punctuation except for a period (".").

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.

.NET Framework

Supported in: 4.5.2, 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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft