本文整理汇总了VB.NET中System.Text.RegularExpressions.Regex.CompileToAssembly方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Regex.CompileToAssembly方法的具体用法?VB.NET Regex.CompileToAssembly怎么用?VB.NET Regex.CompileToAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.CompileToAssembly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: RegexCompilationTest
' 导入命名空间
Imports System.Collections.Generic
Imports System.Reflection
Imports System.Text.RegularExpressions
Module RegexCompilationTest
Public Sub Main()
Dim expr As RegexCompilationInfo
Dim compilationList As New List(Of RegexCompilationInfo)
' Define regular expression to detect duplicate words
expr = New RegexCompilationInfo("\b(?<word>\w+)\s+(\k<word>)\b", _
RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant, _
"DuplicatedString", _
"Utilities.RegularExpressions", _
True)
' Add info object to list of objects
compilationList.Add(expr)
' Define regular expression to validate format of email address
expr = New RegexCompilationInfo("^(?("")(""[^""]+?""@)|(([0-9A-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9A-Z])@))" + _
"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9A-Z][-\w]*[0-9A-Z]\.)+[A-Z]{2,6}))$", _
RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant, _
"EmailAddress", _
"Utilities.RegularExpressions", _
True)
' Add info object to list of objects
compilationList.Add(expr)
' Generate assembly with compiled regular expressions
Dim compilationArray(compilationList.Count - 1) As RegexCompilationInfo
Dim assemName As New AssemblyName("RegexLib, Version=1.0.0.1001, Culture=neutral, PublicKeyToken=null")
compilationList.CopyTo(compilationArray)
Regex.CompileToAssembly(compilationArray, assemName)
End Sub
End Module
示例2: Main
' 导入命名空间
Imports Utilities.RegularExpressions
Module CompiledRegexUsage
Public Sub Main()
Dim text As String = "The the quick brown fox fox jumps over the lazy dog dog."
Dim duplicateRegex As New DuplicatedString()
If duplicateRegex.Matches(text).Count > 0 Then
Console.WriteLine("There are {0} duplicate words in {2} '{1}'", _
duplicateRegex.Matches(text).Count, text, vbCrLf)
Else
Console.WriteLine("There are no duplicate words in {1} '{0}'", _
text, vbCrLf)
End If
End Sub
End Module
输出:
There are 3 duplicate words in The the quick brown fox fox jumps over the lazy dog dog.'
示例3: RegexCompilationTest
' 导入命名空间
Imports System.Collections.Generic
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Text.RegularExpressions
Module RegexCompilationTest
Public Sub Main()
Dim expr As RegexCompilationInfo
Dim compilationList As New List(Of RegexCompilationInfo)
' Define regular expression to detect duplicate words
expr = New RegexCompilationInfo("\b(?<word>\w+)\s+(\k<word>)\b", _
RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant, _
"DuplicatedString", _
"Utilities.RegularExpressions", _
True)
' Add info object to list of objects
compilationList.Add(expr)
' Define regular expression to validate format of email address
expr = New RegexCompilationInfo("^(?("")(""[^""]+?""@)|(([0-9A-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9A-Z])@))" + _
"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9A-Z][-\w]*[0-9A-Z]\.)+[A-Z]{2,6}))$", _
RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant, _
"EmailAddress", _
"Utilities.RegularExpressions", _
True)
' Add info object to list of objects
compilationList.Add(expr)
' Apply AssemblyTitle attribute to the new assembly
'
' Define the parameter(s) of the AssemblyTitle attribute's constructor
Dim params() As Type = { GetType(String) }
' Define the assembly's title
Dim paramValues() As Object = { "General-purpose library of compiled regular expressions" }
' Get the ConstructorInfo object representing the attribute's constructor
Dim ctor As ConstructorInfo = GetType(System.Reflection.AssemblyTitleAttribute).GetConstructor(params)
' Create the CustomAttributeBuilder object array
Dim attBuilder() As CustomAttributeBuilder = { New CustomAttributeBuilder(ctor, paramValues) }
' Generate assembly with compiled regular expressions
Dim compilationArray(compilationList.Count - 1) As RegexCompilationInfo
Dim assemName As New AssemblyName("RegexLib, Version=1.0.0.1001, Culture=neutral, PublicKeyToken=null")
compilationList.CopyTo(compilationArray)
Regex.CompileToAssembly(compilationArray, assemName, attBuilder)
End Sub
End Module