Regex.Matches メソッド

定義

入力文字列内で正規表現と一致する対象をすべて検索し、見つかった対象をすべて返します。

オーバーロード

Matches(String, String, RegexOptions, TimeSpan)

指定した一致オプションとタイムアウト間隔を使用して、指定した入力文字列内で、指定した正規表現に一致するすべての箇所を検索します。

Matches(String, String, RegexOptions)

指定した一致オプションを使用して、指定した入力文字列内で、指定した正規表現に一致する箇所をすべて検索します。

Matches(String, Int32)

入力文字列内の指定した開始位置から検索を開始した場合に、その指定入力文字列内で正規表現と一致する対象をすべて検索します。

Matches(String)

指定した入力文字列内で、正規表現と一致する対象をすべて検索します。

Matches(String, String)

指定した入力文字列内で、指定した正規表現に一致する箇所をすべて検索します。

Matches(String, String, RegexOptions, TimeSpan)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

指定した一致オプションとタイムアウト間隔を使用して、指定した入力文字列内で、指定した正規表現に一致するすべての箇所を検索します。

public:
 static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options, TimeSpan matchTimeout);
public static System.Text.RegularExpressions.MatchCollection Matches (string input, string pattern, System.Text.RegularExpressions.RegexOptions options, TimeSpan matchTimeout);
static member Matches : string * string * System.Text.RegularExpressions.RegexOptions * TimeSpan -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String, options As RegexOptions, matchTimeout As TimeSpan) As MatchCollection

パラメーター

input
String

一致する対象を検索する文字列。

pattern
String

一致させる正規表現パターン。

options
RegexOptions

一致オプションを指定する列挙値のビットごとの組み合わせ。

matchTimeout
TimeSpan

タイムアウト期間、またはメソッドがタイムアウトしないことを示す InfiniteMatchTimeout

戻り値

検索によって見つかった Match オブジェクトのコレクション。 一致が見つからない場合は、空のコレクション オブジェクトが返されます。

例外

正規表現の解析エラーが発生しました。

input または patternnull です。

options は、RegexOptions 値のビットごとの正しい組み合わせではありません。

- または -

matchTimeout が負の値か、0 か、または約 24 日を超えています。

次の例では、 メソッドを Matches(String, String, RegexOptions, TimeSpan) 呼び出して、"es" で終わる文内の任意の単語と一致する大文字と小文字を区別した比較を実行します。 次に、 メソッドを Matches(String, String, RegexOptions, TimeSpan) 呼び出して、パターンと入力文字列の大文字と小文字を区別しない比較を実行します。 どちらの場合も、タイムアウト間隔は 1 秒に設定されます。 出力が示すように、2 つのメソッドは異なる結果を返します。

using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      string pattern = @"\b\w+es\b";
      string sentence = "NOTES: Any notes or comments are optional.";
      
      // Call Matches method without specifying any options.
      try {
         foreach (Match match in Regex.Matches(sentence, pattern,
                                               RegexOptions.None,
                                               TimeSpan.FromSeconds(1)))
            Console.WriteLine("Found '{0}' at position {1}", 
                              match.Value, match.Index);
      }
      catch (RegexMatchTimeoutException) {
         // Do Nothing: Assume that timeout represents no match.
      }
      Console.WriteLine();

      // Call Matches method for case-insensitive matching.
      try { 
         foreach (Match match in Regex.Matches(sentence, pattern, RegexOptions.IgnoreCase))
            Console.WriteLine("Found '{0}' at position {1}", 
                              match.Value, match.Index);
      }
      catch (RegexMatchTimeoutException) {}
   }
}
// The example displays the following output:
//       Found 'notes' at position 11
//       
//       Found 'NOTES' at position 0
//       Found 'notes' at position 11
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim sentence As String = "NOTES: Any notes or comments are optional."
      
      ' Call Matches method without specifying any options.
      For Each match As Match In Regex.Matches(sentence, pattern, 
                                               RegexOptions.None, 
                                               TimeSpan.FromSeconds(1))
         Try
            Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
         Catch e As RegexMatchTimeoutException
            ' Do Nothing: Assume that timeout represents no match.
         End Try
      Next
      Console.WriteLine()
      
      ' Call Matches method for case-insensitive matching.
      Try
         For Each match As Match In Regex.Matches(sentence, pattern, 
                                                  RegexOptions.IgnoreCase,
                                                  TimeSpan.FromSeconds(1))
            Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
         Next
      Catch de As RegexMatchTimeoutException
         ' Do Nothing: Assume that timeout represents no match.
      End Try
   End Sub
End Module
' The example displays the following output:
'       Found 'notes' at position 11
'       
'       Found 'NOTES' at position 0
'       Found 'notes' at position 11

正規表現パターン \b\w+es\b は、次の表に示すように定義されています。

パターン 説明
\b ワード境界から照合を開始します。
\w+ 1 つ以上の単語文字に一致します。
es リテラル文字列 "es" と一致します。
\b ワード境界で照合を終了します。

注釈

メソッドは Matches(String, String, RegexOptions, TimeSpan) メソッドに Match(String, String, RegexOptions, TimeSpan) 似ていますが、1 つの一致ではなく、入力文字列で見つかったすべての一致に関する情報を返す点が除きます。 これは、次のコードと同じです。

   try {
      Match match = Regex.Match(input, pattern, options,
                                TimeSpan.FromSeconds(1));
      while (match.Success) {
            // Handle match here...

            match = match.NextMatch();
      }  
   }
   catch (RegexMatchTimeoutException) {
      // Do nothing: assume that exception represents no match.
   }
   Try
      Dim match As Match = Regex.Match(input, pattern, options, 
                                       TimeSpan.FromSeconds(1))
      Do While match.Success
            ' Handle match here...

            match = match.NextMatch()
      Loop  
   Catch e As RegexMatchTimeoutException
      ' Do nothing: assume that exception represents no match.
   End Try

静的 Matches メソッドは、指定された正規表現パターンを Regex 使用してオブジェクトを構築し、インスタンス メソッド Matchesを呼び出すことと同じです。

パラメーターは pattern 、一致する文字列を記号的に記述する正規表現言語要素で構成されます。 正規表現の詳細については、「.NET 正規表現と正規表現言語 - クイック リファレンス」を参照してください

メソッドは Matches 、遅延評価を使用して、返された MatchCollection オブジェクトを設定します。 や などのMatchCollection.CountMatchCollection.CopyToこのコレクションのメンバーにアクセスすると、コレクションがすぐに設定されます。 遅延評価を利用するには、Visual Basic の C# や For Each...Next などのforeachコンストラクトを使用してコレクションを反復処理する必要があります。

遅延評価のため、 メソッドを Matches 呼び出しても例外はスロー RegexMatchTimeoutException されません。 ただし、一致する操作が パラメーターで指定されたタイムアウト間隔を超えた場合、このメソッドによって返されたオブジェクトに対 MatchCollection して操作が実行されると、例外がmatchTimeout スローされます。

注意 (呼び出し元)

パラメーターを 2 秒などの適切な値に設定 matchTimeout することをお勧めします。 を指定してタイムアウトを InfiniteMatchTimeout無効にすると、正規表現エンジンのパフォーマンスが若干向上します。 ただし、タイムアウトは次の条件でのみ無効にする必要があります。

  • 正規表現によって処理される入力が既知の信頼できるソースから派生した場合、または静的テキストで構成されている場合。 ユーザーが動的に入力したテキストは除外されます。

  • 正規表現パターンが完全にテストされ、一致、一致しない、近い一致が効率的に処理されるようにする場合。

  • 正規表現パターンに、近い一致を処理するときに過剰なバックトラッキングを引き起こすことがわかっている言語要素が含まれない場合。

こちらもご覧ください

適用対象

Matches(String, String, RegexOptions)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

指定した一致オプションを使用して、指定した入力文字列内で、指定した正規表現に一致する箇所をすべて検索します。

public:
 static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options);
public static System.Text.RegularExpressions.MatchCollection Matches (string input, string pattern, System.Text.RegularExpressions.RegexOptions options);
static member Matches : string * string * System.Text.RegularExpressions.RegexOptions -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String, options As RegexOptions) As MatchCollection

パラメーター

input
String

一致する対象を検索する文字列。

pattern
String

一致させる正規表現パターン。

options
RegexOptions

一致オプションを指定する列挙値のビットごとの組み合わせ。

戻り値

検索によって見つかった Match オブジェクトのコレクション。 一致が見つからない場合は、空のコレクション オブジェクトが返されます。

例外

正規表現の解析エラーが発生しました。

input または patternnull です。

options は、RegexOptions 値のビットごとの正しい組み合わせではありません。

次の例では、 メソッドを Matches(String, String) 呼び出して文の中で "es" で終わる単語を識別し、 メソッドを Matches(String, String, RegexOptions) 呼び出して、パターンと入力文字列の大文字と小文字を区別しない比較を実行します。 出力が示すように、2 つのメソッドは異なる結果を返します。

using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      string pattern = @"\b\w+es\b";
      string sentence = "NOTES: Any notes or comments are optional.";
      
      // Call Matches method without specifying any options.
      foreach (Match match in Regex.Matches(sentence, pattern))
         Console.WriteLine("Found '{0}' at position {1}", 
                           match.Value, match.Index);
      Console.WriteLine();

      // Call Matches method for case-insensitive matching.
      foreach (Match match in Regex.Matches(sentence, pattern, RegexOptions.IgnoreCase))
         Console.WriteLine("Found '{0}' at position {1}", 
                           match.Value, match.Index);
   }
}
// The example displays the following output:
//       Found 'notes' at position 11
//       
//       Found 'NOTES' at position 0
//       Found 'notes' at position 11
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim sentence As String = "NOTES: Any notes or comments are optional."
      
      ' Call Matches method without specifying any options.
      For Each match As Match In Regex.Matches(sentence, pattern)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
      Console.WriteLine()
      
      ' Call Matches method for case-insensitive matching.
      For Each match As Match In Regex.Matches(sentence, pattern, RegexOptions.IgnoreCase)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
   End Sub
End Module
' The example displays the following output:
'       Found 'notes' at position 11
'       
'       Found 'NOTES' at position 0
'       Found 'notes' at position 11

正規表現パターン \b\w+es\b は、次の表に示すように定義されています。

パターン 説明
\b ワード境界から照合を開始します。
\w+ 1 つ以上の単語文字に一致します。
es リテラル文字列 "es" と一致します。
\b ワード境界で照合を終了します。

注釈

メソッドは Matches(String, String, RegexOptions) メソッドに Match(String, String, RegexOptions) 似ていますが、1 つの一致ではなく、入力文字列で見つかったすべての一致に関する情報を返す点が除きます。 これは、次のコードと同じです。

Match match = Regex.Match(input, pattern, options);
while (match.Success) {
      // Handle match here...

      match = match.NextMatch();
}
Dim match As Match = Regex.Match(input, pattern, options)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop

静的 Matches メソッドは、指定された正規表現パターンを Regex 使用してオブジェクトを構築し、インスタンス メソッド Matchesを呼び出すことと同じです。

パラメーターは pattern 、一致する文字列を記号的に記述する正規表現言語要素で構成されます。 正規表現の詳細については、「.NET 正規表現と正規表現言語 - クイック リファレンス」を参照してください

メソッドは Matches 、遅延評価を使用して、返された MatchCollection オブジェクトを設定します。 や などのMatchCollection.CountMatchCollection.CopyToこのコレクションのメンバーにアクセスすると、コレクションがすぐに設定されます。 遅延評価を利用するには、Visual Basic の C# や For Each...Next などのforeachコンストラクトを使用してコレクションを反復処理する必要があります。

遅延評価のため、 メソッドを Matches(String, String) 呼び出しても例外はスロー RegexMatchTimeoutException されません。 ただし、現在のアプリケーション ドメインの "REGEX_DEFAULT_MATCH_TIMEOUT" プロパティによってタイムアウト間隔が定義され、一致する操作がこのタイムアウト間隔を超えた場合、このメソッドによって返されるオブジェクトに対して操作が実行 MatchCollection されると、例外がスローされます。

注意 (呼び出し元)

このメソッドは、呼び出されるアプリケーション ドメインの既定のタイムアウト値と等しい間隔の後にタイムアウトします。 アプリケーション ドメインに対してタイムアウト値が定義されていない場合は、メソッドのタイムアウトを妨げる値 InfiniteMatchTimeoutが使用されます。 複数のパターンの一致を取得するために推奨される静的メソッドは です Matches(String, String, RegexOptions, TimeSpan)。これにより、タイムアウト間隔を設定できます。

こちらもご覧ください

適用対象

Matches(String, Int32)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

入力文字列内の指定した開始位置から検索を開始した場合に、その指定入力文字列内で正規表現と一致する対象をすべて検索します。

public:
 System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, int startat);
public System.Text.RegularExpressions.MatchCollection Matches (string input, int startat);
member this.Matches : string * int -> System.Text.RegularExpressions.MatchCollection
Public Function Matches (input As String, startat As Integer) As MatchCollection

パラメーター

input
String

一致する対象を検索する文字列。

startat
Int32

入力文字列内の検索を開始する文字位置。

戻り値

検索によって見つかった Match オブジェクトのコレクション。 一致が見つからない場合は、空のコレクション オブジェクトが返されます。

例外

inputnullです。

startat が 0 未満か、input の長さを超えています。

次の例では、 メソッドを Match(String) 使用して文の最初の単語を検索し、"es" で終わる追加の単語を識別するために メソッドを呼び出 Matches(String, Int32) します。

using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      string pattern = @"\b\w+es\b";
      Regex rgx = new Regex(pattern);
      string sentence = "Who writes these notes and uses our paper?";
      
      // Get the first match.
      Match match = rgx.Match(sentence);
      if (match.Success) {
         Console.WriteLine("Found first 'es' in '{0}' at position {1}", 
                           match.Value, match.Index);
         // Get any additional matches.
         foreach (Match m in rgx.Matches(sentence, match.Index + match.Length))
            Console.WriteLine("Also found '{0}' at position {1}", 
                              m.Value, m.Index);
      }   
   }
}
// The example displays the following output:
//       Found first 'es' in 'writes' at position 4
//       Also found 'notes' at position 17
//       Also found 'uses' at position 27
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim rgx As New Regex(pattern)
      Dim sentence As String = "Who writes these notes and uses our paper?"
      
      ' Get the first match.
      Dim match As Match = rgx.Match(sentence)
      If match.Success Then
         Console.WriteLine("Found first 'es' in '{0}' at position {1}", _
                           match.Value, match.Index)
         ' Get any additional matches.
         For Each match In rgx.Matches(sentence, match.Index + match.Length)
            Console.WriteLine("Also found '{0}' at position {1}", _
                              match.Value, match.Index)
         Next
      End If   
   End Sub
End Module
' The example displays the following output:
'       Found first 'es' in 'writes' at position 4
'       Also found 'notes' at position 17
'       Also found 'uses' at position 27

正規表現パターン \b\w+es\b は、次の表に示すように定義されています。

パターン 説明
\b ワード境界から照合を開始します。
\w+ 1 つ以上の単語文字に一致します。
es リテラル文字列 "es" と一致します。
\b ワード境界で照合を終了します。

注釈

メソッドは Matches(String, Int32) メソッドに Match(String, Int32) 似ていますが、1 つの一致ではなく、入力文字列で見つかったすべての一致に関する情報を返す点が除きます。 これは、次のコードと同じです。

Match match = regex.Match(input, startAt);
while (match.Success) {
      // Handle match here...

      match = match.NextMatch();
}
Dim match As Match = regex.Match(input, startAt)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop

メソッドが検索する Matches(String, Int32) 正規表現パターンは、クラス コンストラクターの Regex 1 つを呼び出すことによって定義されます。 正規表現パターンを形成できる要素の詳細については、「正規表現 言語 - クイック リファレンス」を参照してください

の詳細 startatについては、 の「解説」セクション Match(String, Int32)を参照してください。

メソッドは Matches 、遅延評価を使用して、返される MatchCollection オブジェクトを設定します。 や などのMatchCollection.CountMatchCollection.CopyToこのコレクションのメンバーにアクセスすると、コレクションが直ちに設定されます。 遅延評価を利用するには、Visual Basic の C# や For Each...Next などのforeachコンストラクトを使用してコレクションを反復処理する必要があります。

遅延評価のため、 メソッドを Matches(String, Int32) 呼び出しても例外は RegexMatchTimeoutException スローされません。 ただし、 プロパティが でなくRegex.InfiniteMatchTimeout、一致する操作がタイムアウト間隔をMatchCollection超えると、MatchTimeoutこのメソッドによって返されるオブジェクトに対して操作が実行されると、例外がスローされます。

こちらもご覧ください

適用対象

Matches(String)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

指定した入力文字列内で、正規表現と一致する対象をすべて検索します。

public:
 System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input);
public System.Text.RegularExpressions.MatchCollection Matches (string input);
member this.Matches : string -> System.Text.RegularExpressions.MatchCollection
Public Function Matches (input As String) As MatchCollection

パラメーター

input
String

一致する対象を検索する文字列。

戻り値

検索によって見つかった Match オブジェクトのコレクション。 一致が見つからない場合は、空のコレクション オブジェクトが返されます。

例外

inputnullです。

次の例では、 メソッドを Matches(String) 使用して、文内の "es" で終わる単語を識別します。

using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      string pattern = @"\b\w+es\b";
      Regex rgx = new Regex(pattern);
      string sentence = "Who writes these notes?";
      
      foreach (Match match in rgx.Matches(sentence))
         Console.WriteLine("Found '{0}' at position {1}", 
                           match.Value, match.Index);
   }
}
// The example displays the following output:
//       Found 'writes' at position 4
//       Found 'notes' at position 17
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim rgx As New Regex(pattern)
      Dim sentence As String = "Who writes these notes?"
      
      For Each match As Match In rgx.Matches(sentence)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
   End Sub
End Module
' The example displays the following output:
'       Found 'writes' at position 4
'       Found 'notes' at position 17

正規表現パターン \b\w+es\b は、次の表に示すように定義されています。

パターン 説明
\b ワード境界から照合を開始します。
\w+ 1 つ以上の単語文字に一致します。
es リテラル文字列 "es" と一致します。
\b ワード境界で照合を終了します。

注釈

メソッドは Matches(String) メソッドに Match(String) 似ていますが、1 つの一致ではなく、入力文字列内のすべての一致に関する情報を返す点が異なります。 これは、次のコードと同じです。

Match match = regex.Match(input);
while (match.Success) {
      // Handle match here...

      match = match.NextMatch();
}
Dim match As Match = regex.Match(input)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop

コレクションには一致のみが含まれており、最初に一致しない場合は 終了します。

メソッドが検索する Matches(String) 正規表現パターンは、クラス コンストラクターの Regex 1 つを呼び出すことによって定義されます。 正規表現パターンを形成できる要素の詳細については、「正規表現 言語 - クイック リファレンス」を参照してください

メソッドは Matches 、遅延評価を使用して、返される MatchCollection オブジェクトを設定します。 や などのMatchCollection.CountMatchCollection.CopyToこのコレクションのメンバーにアクセスすると、コレクションが直ちに設定されます。 遅延評価を利用するには、Visual Basic の C# や For Each...Next などのforeachコンストラクトを使用してコレクションを反復処理する必要があります。

遅延評価のため、 メソッドを Matches(String) 呼び出しても例外は RegexMatchTimeoutException スローされません。 ただし、 プロパティが でなくRegex.InfiniteMatchTimeout、一致する操作がタイムアウト間隔をMatchCollection超えると、MatchTimeoutこのメソッドによって返されるオブジェクトに対して操作が実行されると、例外がスローされます。

こちらもご覧ください

適用対象

Matches(String, String)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

指定した入力文字列内で、指定した正規表現に一致する箇所をすべて検索します。

public:
 static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern);
public static System.Text.RegularExpressions.MatchCollection Matches (string input, string pattern);
static member Matches : string * string -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String) As MatchCollection

パラメーター

input
String

一致する対象を検索する文字列。

pattern
String

一致させる正規表現パターン。

戻り値

検索によって見つかった Match オブジェクトのコレクション。 一致が見つからない場合は、空のコレクション オブジェクトが返されます。

例外

正規表現の解析エラーが発生しました。

input または patternnull です。

次の例では、 メソッドを Matches(String, String) 使用して、文内の "es" で終わる単語を識別します。

using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      string pattern = @"\b\w+es\b";
      string sentence = "Who writes these notes?";
      
      foreach (Match match in Regex.Matches(sentence, pattern))
         Console.WriteLine("Found '{0}' at position {1}", 
                           match.Value, match.Index);
   }
}
// The example displays the following output:
//       Found 'writes' at position 4
//       Found 'notes' at position 17
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim sentence As String = "Who writes these notes?"
      For Each match As Match In Regex.Matches(sentence, pattern)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
   End Sub
End Module
' The example displays the following output:
'       Found 'writes' at position 4
'       Found 'notes' at position 17

正規表現パターン \b\w+es\b は、次の表に示すように定義されています。

パターン 説明
\b ワード境界から照合を開始します。
\w+ 1 つ以上の単語文字に一致します。
es リテラル文字列 "es" と一致します。
\b ワード境界で照合を終了します。

注釈

メソッドは Matches(String, String) メソッドに Match(String, String) 似ていますが、1 つの一致ではなく、入力文字列内のすべての一致に関する情報を返す点が異なります。 これは、次のコードと同じです。

Match match = Regex.Match(input, pattern);
while (match.Success) {
      // Handle match here...

      match = match.NextMatch();
}
Dim match As Match = Regex.Match(input, pattern)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop

静的 Matches メソッドは、指定された正規表現パターンを Regex 使用してオブジェクトを構築し、インスタンス メソッド Matchesを呼び出すことと同じです。

パラメーターは pattern 、一致する文字列をシンボル的に記述する正規表現言語要素で構成されます。 正規表現の詳細については、「 .NET 正規表現正規表現言語 - クイック リファレンス」を参照してください

メソッドは Matches 、遅延評価を使用して、返される MatchCollection オブジェクトを設定します。 や などのMatchCollection.CountMatchCollection.CopyToこのコレクションのメンバーにアクセスすると、コレクションが直ちに設定されます。 遅延評価を利用するには、Visual Basic の C# や For Each...Next などのforeachコンストラクトを使用してコレクションを反復処理する必要があります。

遅延評価のため、 メソッドを Matches(String, String) 呼び出しても例外は RegexMatchTimeoutException スローされません。 ただし、現在のアプリケーション ドメインの "REGEX_DEFAULT_MATCH_TIMEOUT" プロパティによってタイムアウト間隔が定義され、一致する操作がこのタイムアウト間隔を超えると、このメソッドによって返されるオブジェクトに対して操作が実行 MatchCollection されると、例外がスローされます。

注意 (呼び出し元)

このメソッドは、呼び出されるアプリケーション ドメインの既定のタイムアウト値と等しい間隔の後にタイムアウトします。 アプリケーション ドメインにタイムアウト値が定義されていない場合は、メソッドのタイムアウトを妨げる値 InfiniteMatchTimeoutが使用されます。 複数のパターン一致を取得するための推奨される静的メソッドは です Matches(String, String, RegexOptions, TimeSpan)。これにより、タイムアウト間隔を指定できます。

こちらもご覧ください

適用対象