Sanibel Logic LLC

...Scalable Technologiesfor the Enterprise

Regular Expression Syntax Testing and Validation

Another common question I get some from licensees of SSLRedirect, HttpCompressionAgent and nUrlRewriter is how to construct meaningful Regular Expressions which will match an incoming URL for the licensee's intended conditions.   Of course, it is my intention to use Regular Expressions within these products because Regular Expressions are an effective tool for testing a broad range of conditions.  However, it is not my intention to educate you on Regular Expression syntax.  I have found a number of Internet sources for such Regular Expression syntax knowledge....simply by Googling "Regular Expressions".

I did develop a Test Regular Expression web page, which allows you to key in an incoming string, followed by a Regular Expression string to see if the Regular Expression will match the incoming string.  CLICK HERE to use this Regular Expression test web page.

The Test Regular Expression web page is illustrated below:

RETest

Regular Expression String Encoding

Sanibel Logic has a number of products which utilize Regular Expressions.  One common question asked by licensees is how to encode Regular Expression strings within the web.config file.  Because the web.config conforms to rules for HTML encoding, any such string must first be HTML encoded, as provided by the .NET System.Web.HttpUtility.HtmlEncode method.  After the string is HTML encoded then we must consider Regular Expression special characters, which must be escaped and include the following special characters:

  • "\" - Backslash
  • "^" - Carat
  • "." - Period
  • "[" - Left bracket
  • "$" - Dollar sign
  • "(" - Left parenthesis
  • ")" - Right parenthesis
  • "|" - Pipe
  • "*" - Asterisk
  • "+" - Plus
  • "?" - Question mark
  • "{" - Left curly bracket

SSLRedirect uses Regular Expression values within the web.config SSLRedirect configuration section, within the urlsIn and urlsOut Xml tags.

HttpCompressionAgent also uses Regular Expression values within its web.config HttpCompression configuration section, within the mimeTypes, urls, assemblies and urlReferrers Xml tags.

To shortcut the process of browsing the Internet, so one can determine how to HTML encode and properly allow for Regular Expression special characters, I have written a basic web transaction which will transform an input Regular Expression string.   Click HERE to try the Regular Expression transformation web transaction.

Sample output from the Regular Expression Transformation web transaction is included for your benefit below...

Regular Expression Transformation Web Transaction