Classe DirectiveRegex

Fornisce un'espressione regolare per l'analisi di una direttiva dati ASP.NET.

Spazio dei nomi: System.Web.RegularExpressions
Assembly: System.Web.RegularExpressions (in system.web.regularexpressions.dll)

Sintassi

'Dichiarazione
Public Class DirectiveRegex
    Inherits Regex
    Implements ISerializable
'Utilizzo
Dim instance As DirectiveRegex
public class DirectiveRegex : Regex, ISerializable
public ref class DirectiveRegex : public Regex, ISerializable
public class DirectiveRegex extends Regex implements ISerializable
public class DirectiveRegex extends Regex implements ISerializable

Note

La classe DirectiveRegex fornisce un'espressione regolare per l'analisi della direttiva dati ASP.NET (<%@%>).

NotaNota

Le classi System.Web.RegularExpressions di .NET Framework sono destinate all'analisi di pagine ASP.NET e non sono sempre ottimali per le applicazioni generali. Molte di queste classi, ad esempio, corrispondono solo all'inizio di una stringa.

Esempio

Nell'esempio di codice che segue viene illustrato come utilizzare la classe DirectiveRegex.

' This example demonstrates the System.Web.RegularExpressions 
' constructors. 
' Each regular expression class is used to match an appropriate 
' string. Note that the System.Web.RegularExpressions classes 
' are intended for internal use and are not always practical for 
' general applications. In particular, many of these regular 
' expressions match only the beginning of a string.

Imports System
Imports System.Text.RegularExpressions
Imports System.Web.RegularExpressions

Class Sample
    Public Shared Sub Main() 
        Dim str1A As String = "<%-- COMMENT BLOCK --%> Initial pattern."
        Dim str1B As String = "Embedded pattern. <%-- COMMENT BLOCK --%>"
        Dim str02 As String = "<% CODE BLOCK %>"
        Dim str03 As String = "<%= EXPRESSION BLOCK %>"
        Dim str04 As String = "<%# DATA BINDING EXPRESSION %>"
        Dim str05 As String = "<%@ DIRECTIVE %>"
        Dim str06 As String = "</END_TAG> xyz"
        Dim str07 As String = "GREATER THAN >"
        Dim str08 As String = "< LESS THAN"
        ' Include directive.
        Dim str09 As String = "<!-- #include file=""filename.ext"" -->"
        ' runat="server" attribute.
        Dim str10 As String = "<script runat=""server"" language=""codelanguage"" src=""pathname"">"
        Dim str11 As String = "<% SERVER TAG %>"
        Dim str12 As String = "abc defg hi jkl <%-- TEXTREGEX --%> mno pqr"
        Dim str13 As String = "<%# DATA BINDING %>"
        Dim str14 As String = "<asp:TAG> ... </asp:TAG>"
        Dim str15 As String = "<%@ SIMPLE DIRECTIVE %>"
        
        ' -------------------------------------------------------------------
        ' Demonstrate that a pattern must occur at the beginning of the 
        ' string. That is, the entire string is not scanned for the pattern.
        ' -------------------------------------------------------------------
        Dim cr As New CommentRegex()
        Display(cr, str1A)
        Display(cr, str1B)
        ' -------------------------------------------------------------------
        Display(New AspCodeRegex(), str02)
        Display(New AspExprRegex(), str03)
        Display(New DatabindExprRegex(), str04)
        Display(New DirectiveRegex(), str05)
        Display(New EndTagRegex(), str06)
        Display(New GTRegex(), str07)
        Display(New LTRegex(), str08)
        Display(New IncludeRegex(), str09)
        Display(New RunatServerRegex(), str10)
        Display(New ServerTagsRegex(), str11)
        Display(New TextRegex(), str12)
        Display(New DataBindRegex(), str13)
        Display(New TagRegex(), str14)
        Display(New SimpleDirectiveRegex(), str15)
    End Sub 'Main
    
    Protected Shared Sub Display(ByVal r As Regex, ByVal s As String) 
        Console.WriteLine("Input: ""{0}""", s)
        Dim m As Match = r.Match(s)
        If m.Success Then
            Console.WriteLine("Match: ""{0}""", m.Value)
        Else
            Console.WriteLine("There is no match.")
        End If
        Console.WriteLine()
    End Sub 'Display
End Class 'Sample
'
'This code example produces the following results:
'
'Input: "<%-- COMMENT BLOCK --%> Initial pattern."
'Match: "<%-- COMMENT BLOCK --%>"
'
'Input: "Embedded pattern. <%-- COMMENT BLOCK --%>"
'There is no match.
'
'Input: "<% CODE BLOCK %>"
'Match: "<% CODE BLOCK %>"
'
'Input: "<%= EXPRESSION BLOCK %>"
'Match: "<%= EXPRESSION BLOCK %>"
'
'Input: "<%# DATA BINDING EXPRESSION %>"
'Match: "<%# DATA BINDING EXPRESSION %>"
'
'Input: "<%@ DIRECTIVE %>"
'Match: "<%@ DIRECTIVE %>"
'
'Input: "</END_TAG> xyz"
'Match: "</END_TAG>"
'
'Input: "GREATER THAN >"
'Match: " >"
'
'Input: "< LESS THAN"
'Match: "< "
'
'Input: "<!-- #include file="filename.ext" -->"
'Match: "<!-- #include file="filename.ext" -->"
'
'Input: "<script runat="server" language="codelanguage" src="pathname">"
'Match: "runat="server"
'
'Input: "<% SERVER TAG %>"
'Match: "<% SERVER TAG %>"
'
'Input: "abc defg hi jkl <%-- TEXTREGEX --%> mno pqr"
'Match: "abc defg hi jkl "
'
'Input: "<%# DATA BINDING %>"
'Match: "<%# DATA BINDING %>"
'
'Input: "<asp:TAG> ... </asp:TAG>"
'Match: "<asp:TAG>"
'
'Input: "<%@ SIMPLE DIRECTIVE %>"
'Match: "<%@ SIMPLE DIRECTIVE %>"
'
// This example demonstrates the System.Web.RegularExpressions 
// constructors. 
// Each regular expression class is used to match an appropriate 
// string. Note that the System.Web.RegularExpressions classes 
// are intended for internal use and are not always practical for 
// general applications. In particular, many of these regular 
// expressions match only the beginning of a string.

using System;
using System.Text.RegularExpressions;
using System.Web.RegularExpressions;

class Sample 
{
    public static void Main() 
    {
    string str1A = "<%-- COMMENT BLOCK --%> Initial pattern.";
    string str1B = "Embedded pattern. <%-- COMMENT BLOCK --%>";
    string str02 = "<% CODE BLOCK %>";
    string str03 = "<%= EXPRESSION BLOCK %>";
    string str04 = "<%# DATA BINDING EXPRESSION %>";
    string str05 = "<%@ DIRECTIVE %>";
    string str06 = "</END_TAG> xyz";
    string str07 = "GREATER THAN >";
    string str08 = "< LESS THAN";
                                     // Include directive.
    string str09 = @"<!-- #include file=""filename.ext"" -->"; 
                                     // runat="server" attribute.
    string str10 = @"<script runat=""server"" " + 
                   @"language=""codelanguage"" src=""pathname"">";
    string str11 = "<% SERVER TAG %>";
    string str12 = "abc defg hi jkl <%-- TEXTREGEX --%> mno pqr";
    string str13 = "<%# DATA BINDING %>";
    string str14 = "<asp:TAG> ... </asp:TAG>";
    string str15 = "<%@ SIMPLE DIRECTIVE %>";

// -------------------------------------------------------------------
// Demonstrate that a pattern must occur at the beginning of the 
// string. That is, the entire string is not scanned for the pattern.
// -------------------------------------------------------------------
    CommentRegex cr = new CommentRegex();
    Display(cr, str1A);
    Display(cr, str1B);
// -------------------------------------------------------------------

    Display(new AspCodeRegex(),         str02);
    Display(new AspExprRegex(),         str03);
    Display(new DatabindExprRegex(),    str04);
    Display(new DirectiveRegex(),       str05);
    Display(new EndTagRegex(),          str06);
    Display(new GTRegex(),              str07);
    Display(new LTRegex(),              str08);
    Display(new IncludeRegex(),         str09);
    Display(new RunatServerRegex(),     str10);
    Display(new ServerTagsRegex(),      str11);
    Display(new TextRegex(),            str12);
    Display(new DataBindRegex(),        str13);
    Display(new TagRegex(),             str14);
    Display(new SimpleDirectiveRegex(), str15);
    }

    protected static void Display(Regex r, string s) 
    {
    Console.WriteLine("Input: \"{0}\"", s);
    Match m = r.Match(s);
    if (m.Success)
        Console.WriteLine("Match: \"{0}\"", m.Value);
    else
        Console.WriteLine("There is no match.");
    Console.WriteLine();
    }
}
/*
This code example produces the following results:

Input: "<%-- COMMENT BLOCK --%> Initial pattern."
Match: "<%-- COMMENT BLOCK --%>"

Input: "Embedded pattern. <%-- COMMENT BLOCK --%>"
There is no match.

Input: "<% CODE BLOCK %>"
Match: "<% CODE BLOCK %>"

Input: "<%= EXPRESSION BLOCK %>"
Match: "<%= EXPRESSION BLOCK %>"

Input: "<%# DATA BINDING EXPRESSION %>"
Match: "<%# DATA BINDING EXPRESSION %>"

Input: "<%@ DIRECTIVE %>"
Match: "<%@ DIRECTIVE %>"

Input: "</END_TAG> xyz"
Match: "</END_TAG>"

Input: "GREATER THAN >"
Match: " >"

Input: "< LESS THAN"
Match: "< "

Input: "<!-- #include file="filename.ext" -->"
Match: "<!-- #include file="filename.ext" -->"

Input: "<script runat="server" language="codelanguage" src="pathname">"
Match: "runat="server"

Input: "<% SERVER TAG %>"
Match: "<% SERVER TAG %>"

Input: "abc defg hi jkl <%-- TEXTREGEX --%> mno pqr"
Match: "abc defg hi jkl "

Input: "<%# DATA BINDING %>"
Match: "<%# DATA BINDING %>"

Input: "<asp:TAG> ... </asp:TAG>"
Match: "<asp:TAG>"

Input: "<%@ SIMPLE DIRECTIVE %>"
Match: "<%@ SIMPLE DIRECTIVE %>"
*/

Gerarchia di ereditarietà

System.Object
   System.Text.RegularExpressions.Regex
    System.Web.RegularExpressions.DirectiveRegex

Codice thread safe

I membri statici pubblici (Shared in Visual Basic) di questo tipo sono validi per le operazioni multithreading. I membri di istanza non sono garantiti come thread safe.

Piattaforme

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 non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

Informazioni sulla versione

.NET Framework

Supportato in: 2.0 1.1 1.0

Vedere anche

Riferimenti

Membri DirectiveRegex
Spazio dei nomi System.Web.RegularExpressions
Classe Regex
SimpleDirectiveRegex