RegexCompilationInfo コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > RegexCompilationInfo コンストラクタの意味・解説 

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 名前空間



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

辞書ショートカット

すべての辞書の索引

「RegexCompilationInfo コンストラクタ」の関連用語

RegexCompilationInfo コンストラクタのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS