RegexCompilationInfo Oluşturucular

Tanım

RegexCompilationInfo sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

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

Bir derlemeye RegexCompilationInfo dahil edilecek normal ifade hakkında bilgi içeren sınıfının yeni bir örneğini başlatır.

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

Bir derlemeye RegexCompilationInfo eklenecek belirtilen zaman aşımı değerine sahip bir normal ifade hakkında bilgi içeren sınıfının yeni bir örneğini başlatır.

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

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

Bir derlemeye RegexCompilationInfo dahil edilecek normal ifade hakkında bilgi içeren sınıfının yeni bir örneğini başlatır.

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)

Parametreler

pattern
String

Derlenecek normal ifade.

options
RegexOptions

Normal ifadeyi derlerken kullanılacak normal ifade seçenekleri.

name
String

Derlenmiş normal ifadeyi temsil eden türün adı.

fullnamespace
String

Yeni türün ait olduğu ad alanı.

ispublic
Boolean

true derlenmiş normal ifadeyi genel olarak görünür hale getirmek için; aksi takdirde , false.

Özel durumlar

name, Empty değeridir.

pattern, null değeridir.

-veya-

name, null değeridir.

-veya-

fullnamespace, null değeridir.

Örnekler

Aşağıdaki örnek, iki adımda derlenmiş bir normal ifade oluşturur ve kullanır.

İlk adımda aşağıdaki kod örneğini derleyin ve yürütelim. RegexCompilationInfo Kod örneğindeki oluşturucu derlenmiş bir normal ifade tanımlar. Kodu yürütmenin sonucu, adlı derlenmiş normal ifade türünü içeren FishRegex.dll adlı FishRegexbir derlemedir.

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

İkinci adımda, FishRegex.dll başvurusunu kullanarak aşağıdaki kod örneğini derleyin ve ardından sonuçta elde edilen yürütülebilir dosyayı çalıştırın. Yürütülebilir dosya, türünü kullanarak bir hedef dizeyle FishRegex eşleşir ve eşleşmelerin eşleşme, grup, yakalama grubu ve dizin konumunu hedef dizede görüntüler.

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

Açıklamalar

Oluşturucunun RegexCompilationInfo(String, RegexOptions, String, String, Boolean) her parametresi doğrudan sınıfının bir özelliğine RegexCompilationInfo karşılık gelir. Tüm özellikler okuma/yazma olduğundan, değerleri doğrudan atanabilir.

yöntemi, CompileToAssembly derlenmiş normal ifadeler içeren bir derleme oluşturur. Bu nedenle, değerlerinden optionsbiri olarak belirtmemelisinizCompiled.

ise ispublictrue, derlenmiş normal ifade sınıfına genel erişilebilirlik verilir. Başka bir ifadeyle, herhangi bir derlemede yürütülen koddan örneklenebilir. ise ispublicfalse, derlenmiş normal ifade sınıfı verilir internal (C#'de) veya Friend (Visual Basic'te) erişilebilirlik. Yani, yalnızca normal ifade sınıfıyla aynı derlemede yürütülen koddan örneklenebilir.

Arayanlara Notlar

Bu oluşturucu, oluşturulduğu uygulama etki alanının varsayılan zaman aşımı değerini kullanan derlenmiş bir normal ifade oluşturur. Uygulama etki alanı için bir zaman aşımı değeri tanımlanmışsa, derlenen normal ifade, desen eşleştirme işleminin zaman aşımına geçmesini engelleyen değerini InfiniteMatchTimeoutkullanır. Derlenmiş normal ifade oluşturmak için önerilen oluşturucu, zaman aşımı aralığını ayarlamanıza olanak tanıyan şeklindedir RegexCompilationInfo(String, RegexOptions, String, String, Boolean, TimeSpan).

Şunlara uygulanır

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

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

Bir derlemeye RegexCompilationInfo eklenecek belirtilen zaman aşımı değerine sahip bir normal ifade hakkında bilgi içeren sınıfının yeni bir örneğini başlatır.

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)

Parametreler

pattern
String

Derlenecek normal ifade.

options
RegexOptions

Normal ifadeyi derlerken kullanılacak normal ifade seçenekleri.

name
String

Derlenmiş normal ifadeyi temsil eden türün adı.

fullnamespace
String

Yeni türün ait olduğu ad alanı.

ispublic
Boolean

true derlenmiş normal ifadeyi genel olarak görünür hale getirmek için; aksi takdirde , false.

matchTimeout
TimeSpan

Normal ifade için varsayılan zaman aşımı aralığı.

Özel durumlar

name, Empty değeridir.

pattern, null değeridir.

-veya-

name, null değeridir.

-veya-

fullnamespace, null değeridir.

matchTimeout negatif, sıfır veya yaklaşık 24 günden büyük.

Örnekler

Aşağıdaki örnek, bir giriş dizesinde aynı karakterin iki veya daha fazla oluşumunu tanımlayan adlı DuplicateChars tek bir derlenmiş normal ifade tanımlar. Derlenen normal ifadenin varsayılan zaman aşımı süresi 2 saniyedir. Örneği yürüttüğünde, derlenmiş normal ifadeyi içeren RegexLib.dll adlı bir sınıf kitaplığı oluşturur.

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

Normal ifade deseni (\w)\1+ aşağıdaki tabloda gösterildiği gibi tanımlanır.

Desen Description
(\w) Herhangi bir sözcük karakterini eşleştirin ve ilk yakalama grubuna atayın.
\1+ Yakalanan ilk grubun değerinin bir veya daha fazla örneğini eşleştirin.

Aşağıdaki örnek, bir dize dizisindeki DuplicatedChars yinelenen karakterleri tanımlamak için normal ifadeyi kullanır. Oluşturucuyu DuplicatedChars çağırdığında zaman aşımı aralığını 0,5 saniye olarak değiştirir.

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

Açıklamalar

Oluşturucunun RegexCompilationInfo(String, RegexOptions, String, String, Boolean) her parametresi doğrudan sınıfının bir özelliğine RegexCompilationInfo karşılık gelir. Tüm özellikler okuma/yazma olduğundan, değerleri doğrudan atanabilir.

yöntemi, CompileToAssembly derlenmiş normal ifadeler içeren bir derleme oluşturur. Bu nedenle, değerlerinden optionsbiri olarak belirtmemelisinizCompiled.

ise ispublictrue, derlenmiş normal ifade sınıfına genel erişilebilirlik verilir. Başka bir ifadeyle, herhangi bir derlemede yürütülen koddan örneklenebilir. ise ispublicfalse, derlenmiş normal ifade sınıfı verilir internal (C#'de) veya Friend (Visual Basic'te) erişilebilirlik. Yani, yalnızca normal ifade sınıfıyla aynı derlemede yürütülen koddan örneklenebilir.

parametresi, matchTimeout derlenen normal ifade için varsayılan zaman aşımı aralığını tanımlar. Bu değer, derlenmiş bir normal ifade nesnesinin işlem zaman aşımına uğramadan ve normal ifade altyapısı bir sonraki zamanlama denetimi sırasında bir özel durum oluşturmadan önce tek bir RegexMatchTimeoutException eşleştirme işlemi yürüteceği yaklaşık süreyi temsil eder. Zaman aşımı değeri hakkında ek bilgi için özelliğine MatchTimeout bakın.

Önemli

Derlenmiş normal ifade için her zaman varsayılan bir zaman aşımı değeri ayarlamanızı öneririz. Normal ifade kitaplığınızın tüketicileri, bu oluşturucu aşırı yüklemesine yeni zaman aşımı aralığını temsil eden bir TimeSpan değer geçirerek bu zaman aşımı değerini geçersiz kılabilir.

Ayrıca bkz.

Şunlara uygulanır