RegexCompilationInfoとは? わかりやすく解説

RegexCompilationInfo クラス

コンパイラが正規表現をコンパイルしてスタンドアロン アセンブリを作成するために使用する情報を提供します。

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

<SerializableAttribute> _
Public Class RegexCompilationInfo
Dim instance As RegexCompilationInfo
[SerializableAttribute] 
public class RegexCompilationInfo
[SerializableAttribute] 
public ref class RegexCompilationInfo
/** @attribute SerializableAttribute() */ 
public class RegexCompilationInfo
SerializableAttribute 
public class RegexCompilationInfo
継承階層継承階層
System.Object
  System.Text.RegularExpressions.RegexCompilationInfo
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RegexCompilationInfo メンバ
System.Text.RegularExpressions 名前空間

RegexCompilationInfo コンストラクタ

アセンブリを作成するためにコンパイラが必要とする情報を格納している RegexCompilationInfo オブジェクトを作成します。

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

Public Sub New ( _
    pattern As String, _
    options As RegexOptions, _
    name As String, _
    fullnamespace As String, _
    ispublic As Boolean _
)
Dim pattern As String
Dim options As RegexOptions
Dim name As String
Dim fullnamespace As String
Dim ispublic As Boolean

Dim instance As New RegexCompilationInfo(pattern,
 options, name, fullnamespace, ispublic)
public RegexCompilationInfo (
    string pattern,
    RegexOptions options,
    string name,
    string fullnamespace,
    bool ispublic
)
public:
RegexCompilationInfo (
    String^ pattern, 
    RegexOptions options, 
    String^ name, 
    String^ fullnamespace, 
    bool ispublic
)
public RegexCompilationInfo (
    String pattern, 
    RegexOptions options, 
    String name, 
    String fullnamespace, 
    boolean ispublic
)
public function RegexCompilationInfo (
    pattern : String, 
    options : RegexOptions, 
    name : String, 
    fullnamespace : String, 
    ispublic : boolean
)

パラメータ

pattern

コンパイルする正規表現。

options

正規表現をコンパイルするときに使用するコンパイラ オプション。

name

コンパイルされた正規表現に使用する型の名前。

fullnamespace

新しい型の追加先の名前空間。

ispublic

コンパイルされた正規表現をパブリックに参照できるようにする場合は true。それ以外の場合は false。

使用例使用例

コンパイルされた正規表現を 3 つの手順で定義、作成、および使用するコード例を次に示します。

1 つ目の手順では、次のコード例をコンパイルします。コード例の RegexCompilationInfo コンストラクタによって、コンパイル対象の正規表現が定義されています。

' This code example demonstrates the RegexCompilationInfo constructor
' and the Regex.CompileToAssembly() method.
' compile: csc genFishRegex.cs

Imports System
Imports System.Reflection
Imports System.Text.RegularExpressions

Class GenFishRegEx
    Public Shared Sub Main()
 
        ' Pattern = Group matches one or more word characters, 
        '           one or more white space characters, 
        '           group matches the string "fish".
        Dim pat As String
 = "(\w+)\s+(fish)"
        
        ' Create the compilation information.
        ' Case-insensitive matching; type name = "FishRegex";
 
        ' namespace = "MyApp"; type is public.
        Dim rci As New RegexCompilationInfo(pat,
 RegexOptions.IgnoreCase, _
                                            "FishRegex",
 "MyApp", True)
        
        ' Setup to compile.
        Dim an As New AssemblyName()
        an.Name = "FishRegex"
        Dim rciList As RegexCompilationInfo()
 = New RegexCompilationInfo() { rci }
        
        ' Compile the regular expression.
        Regex.CompileToAssembly(rciList, an)
    
    End Sub 'Main
End Class 'GenFishRegEx

'
'This code example produces the following results:
'
'(Execute this code to generate the compiled regular 
'expression assembly named FishRegex.dll.
'Use FishRegex.dll as a reference when compiling 
'useFishRegex.cs.)
'
// This code example demonstrates the RegexCompilationInfo constructor
// and the Regex.CompileToAssembly() method.
// compile: csc genFishRegex.cs

namespace MyApp
{
    using System;
    using System.Reflection;
    using System.Text.RegularExpressions;
    class GenFishRegEx
    {
        public static void
 Main()
        {
// Pattern = Group matches one or more word characters, 
//           one or more white space characters, 
//           group matches the string "fish".
        string pat = @"(\w+)\s+(fish)";

// Create the compilation information.
// Case-insensitive matching; type name = "FishRegex"; 
// namespace = "MyApp"; type is public.
        RegexCompilationInfo rci = new RegexCompilationInfo(
                    pat, RegexOptions.IgnoreCase, 
                    "FishRegex", "MyApp", true);

// Setup to compile.
        AssemblyName an = new AssemblyName();
        an.Name = "FishRegex";
        RegexCompilationInfo[] rciList = { rci };

// Compile the regular expression.
        Regex.CompileToAssembly(rciList, an);
        }
    }
}

/*
This code example produces the following results:

(Execute this code to generate the compiled regular 
expression assembly named FishRegex.dll.
Use FishRegex.dll as a reference when compiling 
useFishRegex.cs.)

*/

2 つ目の手順では、手順 1 でコンパイルした実行可能ファイルを実行します。実行可能ファイルにより、FishRegex.dll アセンブリが作成されます。コンパイルされた正規表現型は FishRegex という名前になります。

3 つ目の手順では、FishRegex.dll への参照を使用して次のコード例をコンパイルし、生成された実行可能ファイルを実行します。この実行可能ファイルでは、FishRegex 型を使って、対象文字列内から一致するパターンを検索し、一致した文字列、グループ、キャプチャ グループ、およびインデックス位置を表示します。

' This code example demonstrates the RegexCompilationInfo constructor.
' Execute this code example after executing genFishRegex.exe.
' compile: vbc /r:FishRegex.dll useFishRegex.vb

Imports System
Imports System.Reflection
Imports System.Text.RegularExpressions

Class UseFishRegEx
    Public Shared Sub Main()
 
        ' Match against the following target string.
        Dim targetString As String
 = "One fish two fish red fish blue fish"
        Dim matchCount As Integer
 = 0
        Dim f As New MyApp.FishRegex()
        
        ' Display the target string.
        Console.WriteLine(vbLf & "Input string = """
 & targetString & """")
        
        ' Display each match, capture group, capture, and match position.
        Dim m As Match
        For Each m In f.Matches(targetString)
            matchCount = matchCount + 1
            Console.WriteLine(vbLf & "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)
                    System.Console.WriteLine("Capture("
 & j & ") = """
 & c.ToString() & _
                                             """,
 Position = " & c.Index)
                Next j
            Next i
        Next m
    End Sub 'Main
End Class 'UseFishRegEx

'
'This code example produces the following results:
'
'Input string = "One fish two fish red fish blue fish"
'
'Match(1)
'Group(1) = "One"
'Capture(0) = "One", Position = 0
'Group(2) = "fish"
'Capture(0) = "fish", Position = 4
'
'Match(2)
'Group(1) = "two"
'Capture(0) = "two", Position = 9
'Group(2) = "fish"
'Capture(0) = "fish", Position = 13
'
'Match(3)
'Group(1) = "red"
'Capture(0) = "red", Position = 18
'Group(2) = "fish"
'Capture(0) = "fish", Position = 22
'
'Match(4)
'Group(1) = "blue"
'Capture(0) = "blue", Position = 27
'Group(2) = "fish"
'Capture(0) = "fish", Position = 32
'
// This code example demonstrates the RegexCompilationInfo constructor.
// Execute this code example after executing genFishRegex.exe.
// compile: csc /r:FishRegex.dll useFishRegex.cs

namespace MyApp
  {
  using System;
  using System.Reflection;
  using System.Text.RegularExpressions;

  class UseFishRegEx
    {
    public static void Main()
      {
// Match against the following target string.
      string targetString = "One fish two fish red fish blue
 fish";
      int matchCount = 0;
      FishRegex f = new FishRegex();

// Display the target string.
      Console.WriteLine("\nInput string = \"" +
 targetString + "\"");

// Display each match, capture group, capture, and match position.
      foreach (Match m in f.Matches(targetString))
    {
    Console.WriteLine("\nMatch(" + (++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);
        }
      }
    }
      }
    }
  }

/*
This code example produces the following results:

Input string = "One fish two fish red fish blue fish"

Match(1)
Group(1) = "One"
Capture(0) = "One", Position = 0
Group(2) = "fish"
Capture(0) = "fish", Position = 4

Match(2)
Group(1) = "two"
Capture(0) = "two", Position = 9
Group(2) = "fish"
Capture(0) = "fish", Position = 13

Match(3)
Group(1) = "red"
Capture(0) = "red", Position = 18
Group(2) = "fish"
Capture(0) = "fish", Position = 22

Match(4)
Group(1) = "blue"
Capture(0) = "blue", Position = 27
Group(2) = "fish"
Capture(0) = "fish", Position = 32

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RegexCompilationInfo クラス
RegexCompilationInfo メンバ
System.Text.RegularExpressions 名前空間

RegexCompilationInfo プロパティ


RegexCompilationInfo メソッド


RegexCompilationInfo メンバ

コンパイラが正規表現をコンパイルしてスタンドアロン アセンブリを作成するために使用する情報を提供します。

RegexCompilationInfo データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド RegexCompilationInfo アセンブリを作成するためにコンパイラが必要とする情報を格納している RegexCompilationInfo オブジェクトを作成します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

RegexCompilationInfo クラス
System.Text.RegularExpressions 名前空間



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「RegexCompilationInfo」の関連用語

RegexCompilationInfoのお隣キーワード
検索ランキング

   

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



RegexCompilationInfoのページの著作権

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

©2026 GRAS Group, Inc.RSS