Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Erstellt ein RegexCompilationInfo-Objekt mit den Informationen, die der Compiler zum Erstellen der Assembly benötigt.
Namespace: System.Text.RegularExpressions
Assembly: System (in system.dll)
Syntax
'Declaration
Public Sub New ( _
pattern As String, _
options As RegexOptions, _
name As String, _
fullnamespace As String, _
ispublic As Boolean _
)
'Usage
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
)
Parameter
- pattern
Der reguläre Ausdruck, der kompiliert werden soll.
- options
Die bei der Kompilierung des regulären Ausdrucks zu verwendenden Compileroptionen.
- name
Der Name des für den kompilierten regulären Ausdruck zu verwendenden Typs.
- fullnamespace
Der Namespace, dem der neue Typ hinzugefügt werden soll.
- ispublic
true, um den kompilierten regulären Ausdruck öffentlich sichtbar zu machen, andernfalls false.
Beispiel
Im folgenden Codebeispiel wird in drei Schritten ein kompilierter regulärer Ausdruck definiert, erstellt und verwendet.
Kompilieren Sie im ersten Schritt das folgende Codebeispiel. Der RegexCompilationInfo-Konstruktor im Codebeispiel bereitet einen regulären Ausdruck auf die Kompilierung vor.
' 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.)
*/
Führen Sie im zweiten Schritt die in Schritt eins kompilierte ausführbare Datei aus. Die ausführbare Datei erstellt die Assembly FishRegex.dll und einen Typ eines kompilierten regulären Ausdrucks mit der Bezeichnung FishRegex.
Kompilieren Sie im dritten Schritt das folgende Codebeispiel mit einem Verweis auf FishRegex.dll, und führen Sie diese ausführbare Datei dann aus. Die ausführbare Datei vergleicht anhand des Typs FishRegex auf eine Zielzeichenfolge und zeigt die Übereinstimmung, die Gruppe, den Fundort und die Indexposition der Übereinstimmungen in der Zielzeichenfolge an.
' 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
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
RegexCompilationInfo-Klasse
RegexCompilationInfo-Member
System.Text.RegularExpressions-Namespace