CaptureCollection CaptureCollection CaptureCollection CaptureCollection Class

定義

単一キャプチャ グループによるキャプチャのセットを表します。Represents the set of captures made by a single capturing group.

public ref class CaptureCollection : System::Collections::ICollection
[System.Serializable]
public class CaptureCollection : System.Collections.ICollection
type CaptureCollection = class
    interface ICollection
    interface IEnumerable
Public Class CaptureCollection
Implements ICollection
継承
CaptureCollectionCaptureCollectionCaptureCollectionCaptureCollection
属性
実装

次の例では、比較、Capture内のオブジェクト、CaptureCollectionによって返されるオブジェクト、Group.CapturesMatch.Capturesプロパティ。The following example compares the Capture objects in the CaptureCollection object returned by the Group.Captures and Match.Captures properties. 比較GroupオブジェクトをCapture内のオブジェクト、CaptureCollectionによって返される、Group.Capturesプロパティ。It also compares Group objects with the Capture objects in the CaptureCollection returned by the Group.Captures property. この例では、次の 2 つの正規表現を使用して、1 つの入力文字列内の一致を検索します。The example uses the following two regular expressions to find matches in a single input string:

  • \b\w+\W{1,2}

    この正規表現パターンでは、1 つまたは複数の単語文字、空白や句読点などの 1 つまたは 2 つの非単語文字に続くから成る単語を識別します。This regular expression pattern identifies a word that consists of one or more word characters, followed by either one or two non-word characters such as white space or punctuation. 正規表現では、キャプチャ グループは含まれません。The regular expression does not include any capturing groups. 例の出力に示す両方、MatchオブジェクトとCaptureCollectionによって返されるオブジェクト、Group.CapturesMatch.Capturesプロパティが同じ一致に関する情報が含まれます。The output from the example shows that both the Match object and the CaptureCollection objects returned by the Group.Captures and Match.Captures properties contain information about the same match.

  • (\b\w+\W{1,2})+

    この正規表現パターンでは、文中の単語を識別します。This regular expression pattern identifies the words in a sentence. パターンは、1 つまたは複数の単語文字の後に 1 つまたは 2 つの非単語文字で構成される単一のキャプチャ グループを定義します。The pattern defines a single capturing group that consists of one or more word characters followed by one or two non-word characters. 正規表現パターンを使用して、+量指定子をこのグループの 1 つ以上の出現と一致します。The regular expression pattern uses the + quantifier to match one or more occurrences of this group. この例の出力を示しています、MatchオブジェクトとCaptureCollectionによって返されるオブジェクト、Match.Capturesプロパティは、同じ一致に関する情報を含めることができます。The output from this example shows that the Match object and the CaptureCollection object returned by the Match.Captures property contain information about the same match. 2 番目のGroupが最後に、文字列のキャプチャのみを正規表現の唯一のキャプチャ グループに対応するオブジェクトが識別、CaptureCollection最初のキャプチャ グループによって返されるオブジェクトGroup.Capturesプロパティがすべて含まれていますキャプチャした部分文字列。The second Group object, which corresponds to the only capturing group in the regular expression, identifies only the last captured string, whereas the CaptureCollection object returned by the first capturing group's Group.Captures property includes all captured substrings.

using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      string pattern;  
      string input = "The young, hairy, and tall dog slowly walked across the yard.";
      Match match;

      // Match a word with a pattern that has no capturing groups.
      pattern = @"\b\w+\W{1,2}";
      match = Regex.Match(input, pattern);
      Console.WriteLine("Pattern: " + pattern);
      Console.WriteLine("Match: " + match.Value);
      Console.WriteLine("  Match.Captures: {0}", match.Captures.Count);
      for (int ctr = 0; ctr < match.Captures.Count; ctr++)
         Console.WriteLine("    {0}: '{1}'", ctr, match.Captures[ctr].Value);
      Console.WriteLine("  Match.Groups: {0}", match.Groups.Count);
      for (int groupCtr = 0; groupCtr < match.Groups.Count; groupCtr++)
      {
         Console.WriteLine("    Group {0}: '{1}'", 
                           groupCtr, match.Groups[groupCtr].Value);
         Console.WriteLine("    Group({0}).Captures: {1}", 
                           groupCtr, match.Groups[groupCtr].Captures.Count);
         for (int captureCtr = 0; captureCtr < match.Groups[groupCtr].Captures.Count; captureCtr++)
            Console.WriteLine("      Capture {0}: '{1}'", 
                              captureCtr, 
                              match.Groups[groupCtr].Captures[captureCtr].Value);
      }
      Console.WriteLine("-----\n");

      // Match a sentence with a pattern that has a quantifier that 
      // applies to the entire group.
      pattern = @"(\b\w+\W{1,2})+";
      match = Regex.Match(input, pattern);
      Console.WriteLine("Pattern: " + pattern);
      Console.WriteLine("Match: " + match.Value);
      Console.WriteLine("  Match.Captures: {0}", match.Captures.Count);
      for (int ctr = 0; ctr < match.Captures.Count; ctr++)
         Console.WriteLine("    {0}: '{1}'", ctr, match.Captures[ctr].Value);
      
      Console.WriteLine("  Match.Groups: {0}", match.Groups.Count);
      for (int groupCtr = 0; groupCtr < match.Groups.Count; groupCtr++)
      {
         Console.WriteLine("    Group {0}: '{1}'", groupCtr, match.Groups[groupCtr].Value);
         Console.WriteLine("    Group({0}).Captures: {1}", 
                           groupCtr, match.Groups[groupCtr].Captures.Count);
         for (int captureCtr = 0; captureCtr < match.Groups[groupCtr].Captures.Count; captureCtr++)
            Console.WriteLine("      Capture {0}: '{1}'", captureCtr, match.Groups[groupCtr].Captures[captureCtr].Value);
      }
   }
}
// The example displays the following output:
//    Pattern: \b\w+\W{1,2}
//    Match: The
//      Match.Captures: 1
//        0: 'The '
//      Match.Groups: 1
//        Group 0: 'The '
//        Group(0).Captures: 1
//          Capture 0: 'The '
//    -----
//    
//    Pattern: (\b\w+\W{1,2})+
//    Match: The young, hairy, and tall dog slowly walked across the yard.
//      Match.Captures: 1
//        0: 'The young, hairy, and tall dog slowly walked across the yard.'
//      Match.Groups: 2
//        Group 0: 'The young, hairy, and tall dog slowly walked across the yard.'
//        Group(0).Captures: 1
//          Capture 0: 'The young, hairy, and tall dog slowly walked across the yard.'
//        Group 1: 'yard.'
//        Group(1).Captures: 11
//          Capture 0: 'The '
//          Capture 1: 'young, '
//          Capture 2: 'hairy, '
//          Capture 3: 'and '
//          Capture 4: 'tall '
//          Capture 5: 'dog '
//          Capture 6: 'slowly '
//          Capture 7: 'walked '
//          Capture 8: 'across '
//          Capture 9: 'the '
//          Capture 10: 'yard.'
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String  
      Dim input As String = "The young, hairy, and tall dog slowly walked across the yard."
      Dim match As Match

      ' Match a word with a pattern that has no capturing groups.
      pattern = "\b\w+\W{1,2}"
      match = Regex.Match(input, pattern)
      Console.WriteLine("Pattern: " + pattern)
      Console.WriteLine("Match: " + match.Value)
      Console.WriteLine("  Match.Captures: {0}", match.Captures.Count)
      For ctr As Integer = 0 To match.Captures.Count - 1
         Console.WriteLine("    {0}: '{1}'", ctr, match.Captures(ctr).Value)
      Next
      Console.WriteLine("  Match.Groups: {0}", match.Groups.Count)
      For groupCtr As Integer = 0 To match.Groups.Count - 1
         Console.WriteLine("    Group {0}: '{1}'", groupCtr, match.Groups(groupCtr).Value)
         Console.WriteLine("    Group({0}).Captures: {1}", _
                           groupCtr, match.Groups(groupCtr).Captures.Count)
         For captureCtr As Integer = 0 To match.Groups(groupCtr).Captures.Count - 1
            Console.WriteLine("      Capture {0}: '{1}'", _
                              captureCtr, _
                              match.Groups(groupCtr).Captures(captureCtr).Value)
         Next
      Next
      Console.WriteLine("-----")
      Console.WriteLine()

      ' Match a sentence with a pattern that has a quantifier that 
      ' applies to the entire group.
      pattern = "(\b\w+\W{1,2})+"
      match = Regex.Match(input, pattern)
      Console.WriteLine("Pattern: " + pattern)
      Console.WriteLine("Match: " + match.Value)
      Console.WriteLine("  Match.Captures: {0}", match.Captures.Count)
      For ctr As Integer = 0 To match.Captures.Count - 1
         Console.WriteLine("    {0}: '{1}'", ctr, match.Captures(ctr).Value)
      Next
      Console.WriteLine("  Match.Groups: {0}", match.Groups.Count)
      For groupCtr As Integer = 0 To match.Groups.Count - 1
         Console.WriteLine("    Group {0}: '{1}'", groupCtr, match.Groups(groupCtr).Value)
         Console.WriteLine("    Group({0}).Captures: {1}", _
                           groupCtr, match.Groups(groupCtr).Captures.Count)
         For captureCtr As Integer = 0 To match.Groups(groupCtr).Captures.Count - 1
            Console.WriteLine("      Capture {0}: '{1}'", captureCtr, match.Groups(groupCtr).Captures(captureCtr).Value)
         Next
      Next
   End Sub
End Module
' The example displays the following output:
'    Pattern: \b\w+\W{1,2}
'    Match: The
'      Match.Captures: 1
'        0: 'The '
'      Match.Groups: 1
'        Group 0: 'The '
'        Group(0).Captures: 1
'          Capture 0: 'The '
'    -----
'    
'    Pattern: (\b\w+\W{1,2})+
'    Match: The young, hairy, and tall dog slowly walked across the yard.
'      Match.Captures: 1
'        0: 'The young, hairy, and tall dog slowly walked across the yard.'
'      Match.Groups: 2
'        Group 0: 'The young, hairy, and tall dog slowly walked across the yard.'
'        Group(0).Captures: 1
'          Capture 0: 'The young, hairy, and tall dog slowly walked across the yard.'
'        Group 1: 'yard.'
'        Group(1).Captures: 11
'          Capture 0: 'The '
'          Capture 1: 'young, '
'          Capture 2: 'hairy, '
'          Capture 3: 'and '
'          Capture 4: 'tall '
'          Capture 5: 'dog '
'          Capture 6: 'slowly '
'          Capture 7: 'walked '
'          Capture 8: 'across '
'          Capture 9: 'the '
'          Capture 10: 'yard.'

注釈

コレクションは変更不可 (読み取り専用) をパブリック コンス トラクターを持ちません。The collection is immutable (read-only) and has no public constructor. CaptureCollectionオブジェクトは、1 つ以上含まれています。Captureオブジェクト。The CaptureCollection object contains one or more Capture objects.

インスタンス、CaptureCollectionクラスは、次のプロパティによって返されます。Instances of the CaptureCollection class are returned by the following properties:

  • Group.Captures プロパティ。The Group.Captures property. コレクションの各メンバーは、キャプチャ グループによってキャプチャされた部分文字列を表します。Each member of the collection represents a substring captured by a capturing group. 量指定子は、キャプチャ グループに適用されていない場合、CaptureCollectionが 1 つには含まれていますCaptureキャプチャされた部分文字列としての同じを表すオブジェクトをGroupオブジェクト。If a quantifier is not applied to a capturing group, the CaptureCollection includes a single Capture object that represents the same captured substring as the Group object. 量指定子は、キャプチャ グループに適用されている場合、CaptureCollectionいずれかが含まれていますCapture各オブジェクトは、部分文字列をキャプチャし、Groupオブジェクトが最後のキャプチャされた部分文字列のみに関する情報を提供します。If a quantifier is applied to a capturing group, the CaptureCollection includes one Capture object for each captured substring, and the Group object provides information only about the last captured substring.

  • Match.Captures プロパティ。The Match.Captures property. ここでは、1 つは、コレクションCapture全体として、一致に関する情報を提供するオブジェクト。In this case, the collection consists of a single Capture object that provides information about the match as a whole. つまり、CaptureCollectionオブジェクトと同じ情報を提供する、Matchオブジェクト。That is, the CaptureCollection object provides the same information as the Match object.

コレクションのメンバーを反復処理するには、お使いの言語で提供されるコレクションのイテレーション構造を使用する必要があります (などforeach(C#) とFor Each.NextTo iterate through the members of the collection, you should use the collection iteration construct provided by your language (such as foreach in C# and For EachNext Visual Basic) によって返される列挙子を取得する代わりに、GetEnumeratorメソッド。in Visual Basic) instead of retrieving the enumerator that is returned by the GetEnumerator method.

プロパティ

Count Count Count Count

グループによってキャプチャされた部分文字列の数を取得します。Gets the number of substrings captured by the group.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

コレクションが読み取り専用かどうかを示す値を取得します。Gets a value that indicates whether the collection is read only.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

コレクションへのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。Gets a value that indicates whether access to the collection is synchronized (thread-safe).

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

コレクションの個別のメンバーを取得します。Gets an individual member of the collection.

SyncRoot SyncRoot SyncRoot SyncRoot

コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。Gets an object that can be used to synchronize access to the collection.

メソッド

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

指定したインデックスを開始位置として、指定した配列にコレクションのすべての要素をコピーします。Copies all the elements of the collection to the given array beginning at the given index.

CopyTo(Capture[], Int32) CopyTo(Capture[], Int32) CopyTo(Capture[], Int32) CopyTo(Capture[], Int32)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

コレクションを反復処理する列挙子を提供します。Provides an enumerator that iterates through the collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

明示的なインターフェイスの実装

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

指定したインデックスを開始位置として、指定した配列にコレクションのすべての要素をコピーします。Copies all the elements of the collection to the given array beginning at the given index.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

コレクションへのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。Gets a value that indicates whether access to the collection is synchronized (thread-safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。Gets an object that can be used to synchronize access to the collection.

ICollection<Capture>.Add(Capture) ICollection<Capture>.Add(Capture) ICollection<Capture>.Add(Capture) ICollection<Capture>.Add(Capture)
ICollection<Capture>.Clear() ICollection<Capture>.Clear() ICollection<Capture>.Clear() ICollection<Capture>.Clear()
ICollection<Capture>.Contains(Capture) ICollection<Capture>.Contains(Capture) ICollection<Capture>.Contains(Capture) ICollection<Capture>.Contains(Capture)
ICollection<Capture>.Remove(Capture) ICollection<Capture>.Remove(Capture) ICollection<Capture>.Remove(Capture) ICollection<Capture>.Remove(Capture)
IEnumerable<Capture>.GetEnumerator() IEnumerable<Capture>.GetEnumerator() IEnumerable<Capture>.GetEnumerator() IEnumerable<Capture>.GetEnumerator()
IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)
IList.Clear() IList.Clear() IList.Clear() IList.Clear()
IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)
IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)
IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)
IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize
IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]
IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)
IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)
IList<Capture>.IndexOf(Capture) IList<Capture>.IndexOf(Capture) IList<Capture>.IndexOf(Capture) IList<Capture>.IndexOf(Capture)
IList<Capture>.Insert(Int32, Capture) IList<Capture>.Insert(Int32, Capture) IList<Capture>.Insert(Int32, Capture) IList<Capture>.Insert(Int32, Capture)
IList<Capture>.Item[Int32] IList<Capture>.Item[Int32] IList<Capture>.Item[Int32] IList<Capture>.Item[Int32]
IList<Capture>.RemoveAt(Int32) IList<Capture>.RemoveAt(Int32) IList<Capture>.RemoveAt(Int32) IList<Capture>.RemoveAt(Int32)

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

要素をキャストするIEnumerable指定した型にします。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

要素をフィルター処理、IEnumerable指定した型に基づいています。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

クエリの並列化を有効にします。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

変換、IEnumerableIQueryableします。Converts an IEnumerable to an IQueryable.

適用対象

こちらもご覧ください