110
Chapter 7 Using Web Development Languages
Creating a multi-character regular expression
You can use the following rules to build multi-character regular expressions:
•
Parentheses group parts of regular expressions together into grouped
subexpressions that can be treated as a single unit. For example, (ha)+ matches
one or more instances of “ha”.
•
A one-character regular expression or grouped subexpressions followed by an
asterisk (*) matches zero or more occurrences of the regular expression. For
example, [a-z]* matches zero or more lowercase characters.
•
A one-character regular expression or grouped subexpressions followed by a plus
(+) matches one or more occurrences of the regular expression. For example,
[a-z]+ matches one or more lowercase characters.
•
A one-character regular expression or grouped subexpressions followed by a
question mark (?) matches zero or one occurrences of the regular expression. For
example,
xy?z
matches either “xyz” or “xz”.
•
The concatenation of regular expressions creates a regular expression that
matches the corresponding concatenation of strings. For example, [A-Z][a-z]*
matches any word, regardless of case.
•
The OR character (|) allows a choice between two regular expressions. For
example, jell(y|ies) matches either “jelly” or “jellies”.
•
Braces ({}) are used to indicate a range of occurrences of a regular expression, in
the form {m, n} where m is a positive integer equal to or greater than zero
indicating the start of the range and n is equal to or greater than m, indicating the
end of the range. For example, (ba){0,3} matches up to three pairs of the
expression “ba”.
Using a back reference
H for Dreamweaver MX supports back referencing, which allows you to
match text in previously matched sets of parentheses. You can use a backslash
followed by a digit
n
(\n) to refer to the
n
th
parenthesized subexpression.
One example of how you can use back references is searching for doubled words, for
example, to find instances of “is is” or “the the” in text. The following example shows
the syntax you use for back referencing in regular expressions:
("There is is coffee in the the kitchen",
"([A-Za-z]+)[ ]+\1","*","ALL")
This code searches for words that are all letters ([A-Za-z]+) followed by one or more
spaces [ ]+ followed by the first matched subexpression in parentheses. The parser
detects the two occurrences of
is
as well as the two occurrences of
the
and replaces
them with an asterisk, resulting in the following text:
There * coffee in * kitchen
Summary of Contents for HOMESITE
Page 11: ...Contents xi Table of CommandID values 310 Table of SettingID values 314 Glossary 323...
Page 12: ...xii Contents...
Page 20: ...xx About This Book...
Page 28: ...8 Chapter 1 Setting Up the Product...
Page 70: ...50 Chapter 4 Managing Files...
Page 88: ...68 Chapter 5 Writing Code and Web Content...
Page 116: ...96 Chapter 6 Editing Pages...
Page 148: ...128 Chapter 7 Using Web Development Languages...
Page 190: ...170 Chapter 11 Deploying Files...
Page 210: ...190 Chapter 12 Testing and Maintaining Web Pages...
Page 216: ...196 Chapter 13 Extending the Help System...
Page 350: ...330 Glossary...
Page 358: ...338 Index...