MatchCollection クラス
アセンブリ: System (system.dll 内)



MatchCollection クラスを使用し、Match インスタンスのセットを問い合わせるコード例を次に示します。
using System; using System.Text.RegularExpressions; public class Test { public static void Main () { // Define a regular expression for repeated words. Regex rx = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b" , RegexOptions.Compiled | RegexOptions.IgnoreCase); // Define a test string. string text = "The the quick brown fox fox jumped over the lazy dog dog."; // Find matches. MatchCollection matches = rx.Matches(text); // Report the number of matches found. Console.WriteLine("{0} matches found.", matches.Count); // Report on each match. foreach (Match match in matches) { string word = match.Groups["word"].Value; int index = match.Index; Console.WriteLine("{0} repeated at position {1}", word, index); } } }
#using <System.dll> using namespace System; using namespace System::Text::RegularExpressions; int main() { // Define a regular expression for repeated words. Regex^ rx = gcnew Regex( "\\b(?<word>\\w+)\\s+(\\k<word>)\\b",static_cast<RegexOptions>(RegexOptions::Compiled | RegexOptions::IgnoreCase) ); // Define a test string. String^ text = "The the quick brown fox fox jumped over the lazy dog dog."; // Find matches. MatchCollection^ matches = rx->Matches( text ); // Report the number of matches found. Console::WriteLine( "{0} matches found.", matches->Count ); // Report on each match. for each (Match^ match in matches) { String^ word = match->Groups["word"]->Value; int index = match->Index; Console::WriteLine("{0} repeated at position {1}", word, index); } }
import System.*; import System.Text.RegularExpressions.*; public class Test { public static void main(String[] args) { // Define a regular expression for repeated words. Regex rx = new Regex("\\b(?<word>\\w+)\\s+(\\k<word>)\\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); // Define a test string. String text = "The the quick brown fox fox jumped over the " + "lazy dog dog."; // Find matches. MatchCollection matches = rx.Matches(text); // Report the number of matches found. Console.WriteLine("{0} matches found.", (Int32)matches.get_Count()); // Report on each match. for (int iCtr = 0; iCtr < matches.get_Count(); iCtr++) { Match match = matches.get_Item(iCtr); String word = match.get_Groups().get_Item("word").get_Value(); int index = match.get_Index(); Console.WriteLine("{0} repeated at position {1}", word, (Int32)index); } } //main } //Test

System.Text.RegularExpressions.MatchCollection


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MatchCollection プロパティ
MatchCollection メソッド

名前 | 説明 | |
---|---|---|
![]() | CopyTo | 指定したインデックスを開始位置として、指定した配列にコレクションのすべての要素をコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | Item[i] と同じ順序で列挙子を提供します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

MatchCollection メンバ
正規表現パターンを入力文字列に繰り返し適用したときに、パターンに一致した一連の対象を表します。
MatchCollection データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | CopyTo | 指定したインデックスを開始位置として、指定した配列にコレクションのすべての要素をコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | Item[i] と同じ順序で列挙子を提供します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- MatchCollectionのページへのリンク