
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
557
Chapter 10
CHAPTER 10
Regular Expressions
10.0 Introduction
The .NET Framework Class Library includes the System.Text.RegularExpressions
namespace, which is devoted to creating, executing, and obtaining results from regu-
lar expressions executed against a string.
Regular expressions take the form of a pattern that can be matched to zero or more
characters within a string. The simplest of these patterns, such as
.* (match any-
thing and everything) and
[A-Za-z] (match any letter) are easy to learn, but more
advanced patterns can be difficult to learn and even more difficult to implement cor-
rectly. Learning and understanding regular expressions can take considerable time
and effort, but the work will pay off.
Regular expression patterns can take a simple form—such as a single word or char-
acter—or a much more complex pattern. The more complex patterns can recognize
and match such things as the year portion of a date, all of the
<SCRIPT> tags in an ASP
page, or a phrase in a sentence that varies with each use. The .NET regular expres-
sion classes provide a very flexible and powerful way to do such things as recognize
text, replace text within a string, and split up text into individual sections based on
one or more complex delimiters.
Despite the complexity of regular expression patterns, ...