User Guide

Table Of Contents
141
CHAPTER 7
Using Regular Expressions in Functions
Regular expressions let you perform string matching operations using ColdFusion functions. This
chapter describes how regular expressions work with the following functions:
REFind
REFindNoCase
REReplace
REReplaceNoCase
This chapter does not apply to regular expressions used in the
cfinput and cftextinput tags.
These tags use JavaScript regular expressions, which have a slightly different syntax than
ColdFusion regular expressions. For information on JavaScript regular expressions, see
Chapter 27, “Building Dynamic Forms with cfform Tags,” on page 631.
Contents
About regular expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Regular expression syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Using backreferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Returning matched subexpressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Regular expression examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Types of regular expression technologies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
About regular expressions
In traditional string matching, as used by the ColdFusion Find and Replace functions, you
provide the string pattern to search for and the string to search. The following example searches a
string for the pattern " BIG " and returns a string index if found. The string index is the location
in the search string where the string pattern begins.
<cfset IndexOfOccurrence=Find(" BIG ", "Some BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->