Using Regular Expressions
93
•
The concatenation of regular expressions creates a regular expression that
matches the corresponding concatenation of strings. For example, [A-Z][a-z]*
matches any capitalized word.
•
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 back references
ColdFusion Studio supports back referencing, which allows you to match text in
previously matched sets of parentheses. You can use a slash 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
Anchoring a regular expression to a string
You can anchor all or part of a regular expression to either the beginning or end of
the string being searched:
•
If a caret (^) is at the beginning of a subexpression, the matched string must be at
the beginning of the string being searched.
•
If a dollar sign ($) is at the end of a subexpression, the matched string must be at
the end of the string being searched.
Summary of Contents for ColdFusion Server 5
Page 18: ...xviii About This Book...
Page 26: ...8 Chapter 1 Setting Up the Product...
Page 42: ...24 Chapter 2 Configuring Browsers and Servers...
Page 60: ...42 Chapter 3 Exploring the Workspace...
Page 100: ...82 Chapter 6 Editing Pages...
Page 126: ...108 Chapter 7 Using Web Development Languages...
Page 212: ...194 Chapter 13 Customizing the Development Environment...
Page 320: ...302 Glossary...