MatchCollection クラスとは? わかりやすく解説

MatchCollection クラス

正規表現パターン入力文字列繰り返し適用したときに、パターン一致した一連の対象表します

名前空間: System.Text.RegularExpressions
アセンブリ: System (system.dll 内)
構文構文

<SerializableAttribute> _
Public Class MatchCollection
    Implements ICollection, IEnumerable
Dim instance As MatchCollection
[SerializableAttribute] 
public class MatchCollection : ICollection,
 IEnumerable
[SerializableAttribute] 
public ref class MatchCollection : ICollection,
 IEnumerable
/** @attribute SerializableAttribute() */ 
public class MatchCollection implements ICollection,
 IEnumerable
SerializableAttribute 
public class MatchCollection implements ICollection,
 IEnumerable
解説解説
使用例使用例

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.Object
  System.Text.RegularExpressions.MatchCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MatchCollection メンバ
System.Text.RegularExpressions 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「MatchCollection クラス」の関連用語

MatchCollection クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MatchCollection クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS