User Guide
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
HomeSite+ 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