User Guide

Table Of Contents
Regular expression syntax 143
Basic regular expression syntax
The simplest regular expression contains only a literal characters. The literal characters must
match exactly the text being searched. For example, you can use the regular expression function
REFind to find the string pattern " BIG ", just as you can with the Find function:
<cfset IndexOfOccurrence=REFind(" BIG ", "Some BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->
In this example, REFind must match the exact string pattern " BIG ".
To use the full power of regular expressions, combine literal characters with character sets and
special characters, as in the following example:
<cfset IndexOfOccurrence=REFind(" [A-Z]+ ", "Some BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->
The literal characters of the regular expression consists of the space characters at the beginning
and end of the regular expression. The character set consists of that part of the regular expression
in square brackets. This character set specifies to find a single uppercase letter from A to Z,
inclusive. The plus sign (+) after the square brackets is a special character specifying to find one or
more occurrences of the character set.
If you removed the + from the regular expression in the previous example, " [A-Z] " matches a
literal space, followed by any single uppercase letter, followed by a single space. This regular
expression matches " B " but not " BIG ". The
REFind function returns 0 for the regular
expression, meaning that it did not find a match.
You can construct very complicated regular expressions containing literal characters, character
sets, and special characters. Like any programming language, the more you work with regular
expressions, the more you can accomplish with them. The examples in this section are fairly basic.
For more examples, see “Regular expression examples” on page 157.
Regular expression syntax
This section describes the basic rules for creating regular expressions.
Using character sets
The pattern within the square brackets of a regular expression defines a character set that is used
to match a single character. For example, the regular expression " [A-Za-z] " specifies to match
any single uppercase or lowercase letter enclosed by spaces. In the character set, a hyphen indicates
a range of characters.
The regular expression " B[IAU]G " matches the strings “ BIG “, “ BAG “, and “ BUG “, but does
not match the string " BOG ".
If you specified the regular expression as " B[IA][GN] ", the concatenation of character sets
creates a regular expression that matches the corresponding concatenation of characters in the
search string. This regular expression matches a space, followed by “B”, followed by an “I” or “A”,
followed by a “G” or “N”, followed by a trailing space. The regular expression matches “ BIG ”, “
BAG ”, “BIN ”, and “BAN ”.