Regex.Match メソッド (String, String)
アセンブリ: System (system.dll 内)

Dim input As String Dim pattern As String Dim returnValue As Match returnValue = Regex.Match(input, pattern)
戻り値
正規表現 Match オブジェクト。

静的 Match メソッドは、正規表現パターンを指定して Regex オブジェクトを構築し、インスタンス メソッド Match を呼び出す操作と同じです。この静的メソッドは、Regex オブジェクトを明示的に作成しなくても、正規表現を単独で 1 回だけ使用できるようにする目的で用意されています。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Regex.Match メソッド (String, Int32)
アセンブリ: System (system.dll 内)

Dim instance As Regex Dim input As String Dim startat As Integer Dim returnValue As Match returnValue = instance.Match(input, startat)
戻り値
正規表現 Match オブジェクト。

startat パラメータを使用した、文字列内の開始位置の指定は省略できます。開始位置を指定しない場合は、検索は既定の startat 位置から始まります。正規表現が左から右の方向に検索する場合、既定の startat 位置は間隔の先頭になります。左から右の方向に検索する場合は、startat 位置は間隔の末尾になります。
スキャンが行われないように検索の動作を限定する場合は、\G を使用して正規表現を (左から右のパターンでは左、または右から左のパターンでは右に) 固定します。これにより、確実に startpos から検索が開始するようになります。
Regex が左から右 (既定値) の場合、検索およびスキャンは startat で指定した文字から開始し、右方向に進行します。Regex が右から左の場合 (RightToLeft オプションを使用してオブジェクトが構築された場合)、検索およびスキャンは startat -1 の位置の文字から開始し、左方向に進行します。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Regex.Match メソッド (String, String, RegexOptions)
アセンブリ: System (system.dll 内)

Public Shared Function Match ( _ input As String, _ pattern As String, _ options As RegexOptions _ ) As Match
Dim input As String Dim pattern As String Dim options As RegexOptions Dim returnValue As Match returnValue = Regex.Match(input, pattern, options)
戻り値
正規表現 Match オブジェクト。

スキャンが行われないように検索の動作を限定する場合は、\G を使用して正規表現を (左から右のパターンでは左、または右から左のパターンでは右に) 固定します。これにより、確実に startpos から検索が開始するようになります。
Regex が左から右 (既定値) の場合、検索およびスキャンは startat で指定した文字から開始し、右方向に進行します。Regex が右から左の場合 (RightToLeft オプションを使用してオブジェクトが構築された場合)、検索およびスキャンは startat -1 の位置の文字から開始し、左方向に進行します。
静的 Match メソッドは、パターンを指定して Regex オブジェクトを構築し、インスタンス メソッド Match を呼び出す操作と同じです。この静的メソッドは、Regex オブジェクトを明示的に作成しなくても、正規表現を単独で 1 回だけ使用できるようにする目的で用意されています。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Regex.Match メソッド (String, Int32, Int32)
アセンブリ: System (system.dll 内)

Dim instance As Regex Dim input As String Dim beginning As Integer Dim length As Integer Dim returnValue As Match returnValue = instance.Match(input, beginning, length)
戻り値
正規表現 Match オブジェクト。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Regex.Match メソッド

名前 | 説明 |
---|---|
Regex.Match (String) | 指定した入力文字列内で、Regex コンストラクタで指定された正規表現と一致する対象を 1 つ検索します。 .NET Compact Framework によってサポートされています。 |
Regex.Match (String, Int32) | 入力文字列内の指定した開始位置から検索を開始し、その入力文字列内で正規表現と一致する対象を 1 つ検索します。 .NET Compact Framework によってサポートされています。 |
Regex.Match (String, String) | 指定した入力文字列内で、pattern パラメータで指定された正規表現と一致する対象を検索します。 .NET Compact Framework によってサポートされています。 |
Regex.Match (String, Int32, Int32) | 入力文字列の開始位置および入力文字列長を指定して、その入力文字列内で正規表現と一致する対象を検索します。 .NET Compact Framework によってサポートされています。 |
Regex.Match (String, String, RegexOptions) | options パラメータで一致オプションを指定し、pattern パラメータで指定された正規表現に一致する対象を検索します。 .NET Compact Framework によってサポートされています。 |

Regex.Match メソッド (String)
アセンブリ: System (system.dll 内)

Dim instance As Regex Dim input As String Dim returnValue As Match returnValue = instance.Match(input)
戻り値
正規表現 Match オブジェクト。

正規表現パターンをコンパイルし、文字列から一致するパターンを検索し、一致したグループ、キャプチャ、およびキャプチャ位置を一覧表示するコード例を次に示します。
Dim text As String = "One car red car blue car" Dim pat As String = "(\w+)\s+(car)" ' Compile the regular expression. Dim r As Regex = new Regex(pat, RegexOptions.IgnoreCase) ' Match the regular expression pattern against a text string. Dim m As Match = r.Match(text) Dim matchcount as Integer = 0 While (m.Success) matchCount += 1 Console.WriteLine("Match" & (matchCount)) Dim i As Integer For i = 1 to 2 Dim g as Group = m.Groups(i) Console.WriteLine("Group" & i & "='" & g.ToString() & "'") Dim cc As CaptureCollection = g.Captures Dim j As Integer For j = 0 to cc.Count - 1 Dim c As Capture = cc(j) Console.WriteLine("Capture" & j & "='" & c.ToString() _ & "', Position=" & c.Index) Next j Next i m = m.NextMatch() End While
string text = "One car red car blue car"; string pat = @"(\w+)\s+(car)"; // Compile the regular expression. Regex r = new Regex(pat, RegexOptions.IgnoreCase); // Match the regular expression pattern against a text string. Match m = r.Match(text); int matchCount = 0; while (m.Success) { Console.WriteLine("Match"+ (++matchCount)); for (int i = 1; i <= 2; i++) { Group g = m.Groups[i]; Console.WriteLine("Group"+i+"='" + g + "'"); CaptureCollection cc = g.Captures; for (int j = 0; j < cc.Count; j++) { Capture c = cc[j]; System.Console.WriteLine("Capture"+j+"='" + c + "', Position="+c.Index); } } m = m.NextMatch(); }
String^ text = "One car red car blue car"; String^ pat = "(\\w+)\\s+(car)"; // Compile the regular expression. Regex^ r = gcnew Regex( pat,RegexOptions::IgnoreCase ); // Match the regular expression pattern against a text string. Match^ m = r->Match(text); int matchCount = 0; while ( m->Success ) { Console::WriteLine( "Match{0}", ++matchCount ); for ( int i = 1; i <= 2; i++ ) { Group^ g = m->Groups[ i ]; Console::WriteLine( "Group{0}='{1}'", i, g ); CaptureCollection^ cc = g->Captures; for ( int j = 0; j < cc->Count; j++ ) { Capture^ c = cc[ j ]; System::Console::WriteLine( "Capture{0}='{1}', Position={2}", j, c, c->Index ); } } m = m->NextMatch(); }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からRegex.Matchを検索する場合は、下記のリンクをクリックしてください。

- Regex.Matchのページへのリンク