
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
590
|
Chapter 10: Regular Expressions
of a UNC string. By breaking up the regular expression onto separate lines and add-
ing comments to each line, you have allowed other developers (who might not be
familiar with regular expressions) to more quickly and easily read and maintain your
regular expression.
Typically, you would use the string concatenation and C#-style commenting to com-
ment a regular expression string. However, if you are retrieving the regular expres-
sion from an external source, such as a text file, regular expression–style
commenting (#) is the type to use.
With simpler regular expressions, you can get away with adding a C# comment out-
side of the regular expression string to indicate what it does. But adding comments
to the regular expression itself greatly aids in understanding it.
10.14 Using Built-in Regular Expressions to Parse
ASP.NET Pages
Problem
You need to build a tool that parses ASP.NET pages in order to extract specific bits
of information. This tool could possibly be used to detect whether specific meta tags
are being used or if there are any comments that could expose information useful to
a hacker.
Solution
Use the classes in the System.Web.RegularExpressions namespace. In this recipe you will
focus on mapping out the start and end tags on a page, as shown ...