
110
|
Chapter 7: The .NET Framework Class Library
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
General Multiplier
A set of curly braces with two comma-delimited integer values indicates a
repeated match a specific number of times. The format is
{x,y}, where x and
y are nonnegative integers, and matches if and only if there are at least x but
at most
y instances of the single character preceding the opening bracket. For
example, the regular expression
\da{5,10}\d matches any string beginning
with a single digit, continuing with at least 5 but at most 10
as and ending
with a single digit, as with
0aaaaaa1.
You can leave out one of
x or y. Thus, {x,} means “at least x,” and {,y}
means “at most y.”
Escaped Characters
Several characters have special meaning within regular expression patterns,
such as [ and ?. These characters must be escaped with the backslash char-
acter (
\) before they can be matched as ordinary non-special characters. For
instance,
\[ matches an opening bracket, \? matches a question mark, and \\
matches a backslash.
The System.Text.RegularExpressions namespace has a Regex class, which has
objects that represent regular expressions. Here’s a simple example of using the
Regex class.
Dim matchPattern As New System.Text.RegularExpressions.Regex( _
"\da{3,5}\d")
MsgBox(matchPattern.IsMatch("0a1")) ' Displays False
MsgBox(matchPattern.IsMatch("0aaa1")) ...