Skip to content

Instantly share code, notes, and snippets.

@haacked
Created December 1, 2013 06:32
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save haacked/7729259 to your computer and use it in GitHub Desktop.
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment