Building a Regular Expression Library Source Listing

using System;
using System.Text.RegularExpressions;
using System.Reflection;
namespace RegexLibraryBuilder
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class RegexBuilderMain
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //HtmlTagRegex.
            RegexCompilationInfo[] compInfo = 
            {
                //HtmlTag Regex.
                new RegexCompilationInfo
                (
                    @"<"
                    +    @"(?<endTag>/)?"    //Captures the / if this is an end tag.
                    +    @"(?<tagname>\w+)"    //Captures TagName
                    +    @"("                //Groups tag contents
                    +        @"(\s+"            //Groups attributes
                    +            @"(?<attName>\w+)"  //Attribute name
                    +            @"("                //groups =value portion.
                    +                @"\s*=\s*"            // = 
                    +                @"(?:"        //Groups attribute "value" portion.
                    +                    @"""(?<attVal>[^""]*)"""    // attVal='double quoted'
                    +                    @"|'(?<attVal>[^']*)'"        // attVal='single quoted'
                    +                    @"|(?<attVal>[^'"">\s]+)"    // attVal=urlnospaces
                    +                @")"
                    +            @")?"        //end optional att value portion.
                    +        @")+\s*"        //One or more attribute pairs
                    +        @"|\s*"            //Some white space.
                    +    @")"
                    + @"(?<completeTag>/)?>" //Captures the "/" if this is a complete tag.
                    , RegexOptions.IgnoreCase
                    , "HtmlTagRegex"
                    , "Haack.RegularExpressions"
                    , true
                )
                ,
                // Matches double words.
                new RegexCompilationInfo
                (
                    @"\b(\w+)\s+\1\b"
                    , RegexOptions.None
                    , "DoubleWordRegex"
                    , "Haack.RegularExpressions", true
                )
            };
            AssemblyName assemblyName = new AssemblyName();
            assemblyName.Name = "Haack.RegularExpressions";
            assemblyName.Version = new Version("1.0.0.0");
            Regex.CompileToAssembly(compInfo, assemblyName);
        }
    }
}

What others have said

Requesting Gravatar... you've been HAACKED Oct 25, 2004 4:03 PM
# Using a Regular Expression to Match an HTML Tag
Requesting Gravatar... you've been HAACKED Apr 22, 2005 2:43 PM
# Using a Regular Expression to Match HTML
Requesting Gravatar... Brian Delahunty Jun 04, 2005 5:31 AM
# re: Building a Regular Expression Library Source Listing
You might like to have a look at a little tool that I've wrote that helps with creating Regular Expression Libraries.

It's called "Regex Library Builder" and it's over at http://briandela.com/blog/archive/2005/06/03/284.aspx
Requesting Gravatar... Matías Dec 10, 2007 8:16 AM
# re: Building a Regular Expression Library Source Listing
What does the code above do?
Requesting Gravatar... ology Jul 26, 2008 10:17 AM
# re: Building a Regular Expression Library Source Listing
I would hardly call this a "library." It just looks at HTML. Also, parsing HTML with regular expressions is a known no-no.

What do you have to say?

(will show your gravatar)
Please add 6 and 7 and type the answer here: