Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DatabindExprRegex Class

Provides a regular expression to parse an ASP.NET data-binding expression.

Namespace: System.Web.RegularExpressions
Assembly: System.Web.RegularExpressions (in system.web.regularexpressions.dll)
public class DatabindExprRegex : Regex, ISerializable
public class DatabindExprRegex extends Regex implements ISerializable
public class DatabindExprRegex extends Regex implements ISerializable
Not applicable.

The DatabindExprRegex class provides a regular expression to parse an ASP.NET data-binding expression (<%#%>).

NoteNote:

The System.Web.RegularExpressions classes are meant to be used by the .NET Framework to parse ASP.NET pages and are not always practical for general applications. For example, many of these classes match only the beginning of a string.

The following code example demonstrates the DatabindExprRegex class.

// 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 %>"
*/

System.Object
   System.Text.RegularExpressions.Regex
    System.Web.RegularExpressions.DatabindExprRegex
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.