RegexCompilationInfo 생성자

정의

RegexCompilationInfo 클래스의 새 인스턴스를 초기화합니다.

오버로드

RegexCompilationInfo(String, RegexOptions, String, String, Boolean)

어셈블리에 포함할 정규식에 대한 정보를 포함하는 RegexCompilationInfo 클래스의 새 인스턴스를 초기화합니다.

RegexCompilationInfo(String, RegexOptions, String, String, Boolean, TimeSpan)

어셈블리에 포함할 지정된 시간 제한 값의 정규식에 대한 정보를 포함하는 RegexCompilationInfo 클래스의 새 인스턴스를 초기화합니다.

RegexCompilationInfo(String, RegexOptions, String, String, Boolean)

Source:
RegexCompilationInfo.cs
Source:
RegexCompilationInfo.cs
Source:
RegexCompilationInfo.cs

어셈블리에 포함할 정규식에 대한 정보를 포함하는 RegexCompilationInfo 클래스의 새 인스턴스를 초기화합니다.

public:
 RegexCompilationInfo(System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options, System::String ^ name, System::String ^ fullnamespace, bool ispublic);
public RegexCompilationInfo (string pattern, System.Text.RegularExpressions.RegexOptions options, string name, string fullnamespace, bool ispublic);
new System.Text.RegularExpressions.RegexCompilationInfo : string * System.Text.RegularExpressions.RegexOptions * string * string * bool -> System.Text.RegularExpressions.RegexCompilationInfo
Public Sub New (pattern As String, options As RegexOptions, name As String, fullnamespace As String, ispublic As Boolean)

매개 변수

pattern
String

컴파일할 정규식입니다.

options
RegexOptions

정규식을 컴파일할 때 사용할 정규식 옵션입니다.

name
String

컴파일된 정규식을 나타내는 형식의 이름입니다.

fullnamespace
String

새 형식이 속한 네임스페이스입니다.

ispublic
Boolean

컴파일된 정규식을 공개적으로 표시하려면 true이고, 그렇지 않으면 false입니다.

예외

name이(가) Empty인 경우

pattern이(가) null인 경우

또는

namenull입니다.

또는

fullnamespacenull입니다.

예제

다음 예제에서는 두 단계로 컴파일된 정규식을 만들고 사용합니다.

첫 번째 단계에서는 다음 코드 예제를 컴파일하고 실행합니다. RegexCompilationInfo 코드 예제의 생성자는 컴파일된 정규식을 정의합니다. 코드를 실행한 결과는 라는 컴파일된 정규식 형식 FishRegex을 포함하는 FishRegex.dll 라는 어셈블리입니다.

// 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 demonstrates the RegexCompilationInfo constructor
' and the Regex.CompileToAssembly() method.
' compile: csc genFishRegex.cs

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
End Class

두 번째 단계에서는 FishRegex.dll 대한 참조를 사용하여 다음 코드 예제를 컴파일한 다음 결과 실행 파일을 실행합니다. 실행 파일은 형식을 사용하여 FishRegex 대상 문자열과 일치하고 대상 문자열에서 일치 항목의 일치, 그룹, 캡처 그룹 및 인덱스 위치를 표시합니다.

// 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

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

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
End Class

'
'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(String, RegexOptions, String, String, Boolean) 는 클래스의 속성에 RegexCompilationInfo 직접 해당합니다. 모든 속성은 읽기/쓰기이므로 해당 값을 직접 할당할 수도 있습니다.

메서드는 CompileToAssembly 컴파일된 정규식을 포함하는 어셈블리를 생성합니다. 따라서 을 값 options중 하나로 지정 Compiled 해서는 안 됩니다.

가 이trueispublic 컴파일된 정규식 클래스에 공용 접근성이 부여됩니다. 즉, 모든 어셈블리에서 실행되는 코드에서 인스턴스화할 수 있습니다. 가 이falseispublic 컴파일된 정규식 클래스가 (C#) 또는 Friend (Visual Basic의 경우) 접근성이 제공됩니다 internal . 즉, 정규식 클래스와 동일한 어셈블리에서 실행되는 코드에서만 인스턴스화할 수 있습니다.

호출자 참고

이 생성자는 만들어진 애플리케이션 도메인의 기본 제한 시간 값을 사용 하는 컴파일된 정규식을 만듭니다. 컴파일된 정규식 시간 제한 값을 애플리케이션 도메인에 대 한 정의 값을 사용 InfiniteMatchTimeout, 패턴 일치 작업을 시간 초과 되지 않도록 합니다. 컴파일된 정규식을 만들기 위한 권장 되는 생성자가 RegexCompilationInfo(String, RegexOptions, String, String, Boolean, TimeSpan), 시간 제한 간격을 설정할 수 있습니다.

적용 대상

RegexCompilationInfo(String, RegexOptions, String, String, Boolean, TimeSpan)

Source:
RegexCompilationInfo.cs
Source:
RegexCompilationInfo.cs
Source:
RegexCompilationInfo.cs

어셈블리에 포함할 지정된 시간 제한 값의 정규식에 대한 정보를 포함하는 RegexCompilationInfo 클래스의 새 인스턴스를 초기화합니다.

public:
 RegexCompilationInfo(System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options, System::String ^ name, System::String ^ fullnamespace, bool ispublic, TimeSpan matchTimeout);
public RegexCompilationInfo (string pattern, System.Text.RegularExpressions.RegexOptions options, string name, string fullnamespace, bool ispublic, TimeSpan matchTimeout);
new System.Text.RegularExpressions.RegexCompilationInfo : string * System.Text.RegularExpressions.RegexOptions * string * string * bool * TimeSpan -> System.Text.RegularExpressions.RegexCompilationInfo
Public Sub New (pattern As String, options As RegexOptions, name As String, fullnamespace As String, ispublic As Boolean, matchTimeout As TimeSpan)

매개 변수

pattern
String

컴파일할 정규식입니다.

options
RegexOptions

정규식을 컴파일할 때 사용할 정규식 옵션입니다.

name
String

컴파일된 정규식을 나타내는 형식의 이름입니다.

fullnamespace
String

새 형식이 속한 네임스페이스입니다.

ispublic
Boolean

컴파일된 정규식을 공개적으로 표시하려면 true이고, 그렇지 않으면 false입니다.

matchTimeout
TimeSpan

정규식에 대한 기본 시간 제한 간격입니다.

예외

name이(가) Empty인 경우

pattern이(가) null인 경우

또는

namenull입니다.

또는

fullnamespace이(가) null인 경우

matchTimeout 이 음수, 0 또는 약 24일보다 큽니다.

예제

다음 예제에서는 입력 문자열에서 동일한 문자가 두 개 이상 발생하는 것을 식별하는 라는 DuplicateChars 단일 컴파일된 정규식을 정의합니다. 컴파일된 정규식의 기본 제한 시간은 2초입니다. 예제를 실행하면 컴파일된 정규식을 포함하는 RegexLib.dll 라는 클래스 라이브러리를 만듭니다.

using System;
using System.Reflection;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
        // Match two or more occurrences of the same character.
        string pattern = @"(\w)\1+";
        
        // Use case-insensitive matching. 
        var rci = new RegexCompilationInfo(pattern, RegexOptions.IgnoreCase,
                                           "DuplicateChars", "CustomRegexes", 
                                           true, TimeSpan.FromSeconds(2));

        // Define an assembly to contain the compiled regular expression.
        var an = new AssemblyName();
        an.Name = "RegexLib";
        RegexCompilationInfo[] rciList = { rci };

        // Compile the regular expression and create the assembly.
        Regex.CompileToAssembly(rciList, an);
   }
}
Imports System.Reflection
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
        ' Match two or more occurrences of the same character.
        Dim pattern As String = "(\w)\1+"
        
        ' Use case-insensitive matching. 
        Dim rci As New RegexCompilationInfo(pattern, RegexOptions.IgnoreCase,
                                            "DuplicateChars", "CustomRegexes", 
                                            True, TimeSpan.FromSeconds(2))

        ' Define an assembly to contain the compiled regular expression.
        Dim an As New AssemblyName()
        an.Name = "RegexLib"
        Dim rciList As RegexCompilationInfo() = New RegexCompilationInfo() { rci }

        ' Compile the regular expression and create the assembly.
        Regex.CompileToAssembly(rciList, an)
   End Sub
End Module

정규식 패턴 (\w)\1+ 는 다음 테이블과 같이 정의됩니다.

무늬 설명
(\w) 단어 문자를 일치시키고 첫 번째 캡처 그룹에 할당합니다.
\1+ 캡처된 첫 번째 그룹의 값이 하나 이상 나타나는지 일치합니다.

다음 예제에서는 정규식을 사용하여 DuplicatedChars 문자열 배열에서 중복 문자를 식별합니다. 생성자를 호출 DuplicatedChars 하면 제한 시간 간격이 .5초로 변경됩니다.

using CustomRegexes;
using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      var rgx = new DuplicateChars(TimeSpan.FromSeconds(.5));
      
      string[] values = { "Greeeeeat", "seed", "deed", "beam", 
                          "loop", "Aardvark" };
      // Display regex information.
      Console.WriteLine("Regular Expression Pattern: {0}", rgx);
      Console.WriteLine("Regex timeout value: {0} seconds\n", 
                        rgx.MatchTimeout.TotalSeconds);
      
      // Display matching information.
      foreach (var value in values) {
         Match m = rgx.Match(value);
         if (m.Success)
            Console.WriteLine("'{0}' found in '{1}' at positions {2}-{3}",
                              m.Value, value, m.Index, m.Index + m.Length - 1);
         else
            Console.WriteLine("No match found in '{0}'", value);
      }                                                         
   }
}
// The example displays the following output:
//       Regular Expression Pattern: (\w)\1+
//       Regex timeout value: 0.5 seconds
//       
//       //eeeee// found in //Greeeeeat// at positions 2-6
//       //ee// found in //seed// at positions 1-2
//       //ee// found in //deed// at positions 1-2
//       No match found in //beam//
//       //oo// found in //loop// at positions 1-2
//       //Aa// found in //Aardvark// at positions 0-1
Imports CustomRegexes
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim rgx As New DuplicateChars(TimeSpan.FromSeconds(.5))
      
      Dim values() As String = { "Greeeeeat", "seed", "deed", "beam", 
                                 "loop", "Aardvark" }
      ' Display regex information.
      Console.WriteLine("Regular Expression Pattern: {0}", rgx)
      Console.WriteLine("Regex timeout value: {0} seconds", 
                        rgx.MatchTimeout.TotalSeconds)
      Console.WriteLine()
      
      ' Display matching information.
      For Each value In values
         Dim m As Match = rgx.Match(value)
         If m.Success Then
            Console.WriteLine("'{0}' found in '{1}' at positions {2}-{3}",
                              m.Value, value, m.Index, m.Index + m.Length - 1)
         Else
            Console.WriteLine("No match found in '{0}'", value)
         End If   
      Next                                                         
   End Sub
End Module
' The example displays the following output:
'       Regular Expression Pattern: (\w)\1+
'       Regex timeout value: 0.5 seconds
'       
'       'eeeee' found in 'Greeeeeat' at positions 2-6
'       'ee' found in 'seed' at positions 1-2
'       'ee' found in 'deed' at positions 1-2
'       No match found in 'beam'
'       'oo' found in 'loop' at positions 1-2
'       'Aa' found in 'Aardvark' at positions 0-1

설명

생성자의 각 매개 변수 RegexCompilationInfo(String, RegexOptions, String, String, Boolean) 는 클래스의 속성에 RegexCompilationInfo 직접 해당합니다. 모든 속성은 읽기/쓰기이므로 해당 값을 직접 할당할 수도 있습니다.

메서드는 CompileToAssembly 컴파일된 정규식을 포함하는 어셈블리를 생성합니다. 따라서 을 값 options중 하나로 지정 Compiled 해서는 안 됩니다.

가 이trueispublic 컴파일된 정규식 클래스에 공용 접근성이 부여됩니다. 즉, 모든 어셈블리에서 실행되는 코드에서 인스턴스화할 수 있습니다. 가 이falseispublic 컴파일된 정규식 클래스가 (C#) 또는 Friend (Visual Basic의 경우) 접근성이 제공됩니다 internal . 즉, 정규식 클래스와 동일한 어셈블리에서 실행되는 코드에서만 인스턴스화할 수 있습니다.

매개 변수는 matchTimeout 컴파일된 정규식의 기본 제한 시간 간격을 정의합니다. 이 값은 컴파일된 정규식 개체가 작업 시간이 초과되고 정규식 엔진이 다음 타이밍 검사 동안 예외를 throw RegexMatchTimeoutException 하기 전에 단일 일치 작업을 실행하는 대략적인 시간을 나타냅니다. 제한 시간 값에 대한 자세한 내용은 속성을 참조 MatchTimeout 하세요.

중요

컴파일된 정규식에 대한 기본 제한 시간 값을 항상 설정하는 것이 좋습니다. 정규식 라이브러리의 소비자는 이 생성자 오버로드에 새 시간 제한 간격을 TimeSpan 나타내는 값을 전달하여 해당 시간 제한 값을 재정의할 수 있습니다.

추가 정보

적용 대상