User Guide

Table Of Contents
150 Chapter 7: Using Regular Expressions in Functions
This code replaces all the spaces with *, producing this string:
Macromedia*Web*Site
You can combine character classes with other expressions within a character set. For example, the
regular expression [[:space:]123] searches for a space, 1, 2, or 3. The following example also uses a
character class in a regular expression:
<cfset IndexOfOccurrence=REFind("[[:space:]][A-Z]+[[:space:]]",
"Some BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->
The following table shows the character classes that ColdFusion supports. Regular expressions
using these classes match any Unicode character in the class, not just ASCII or ISO-8859
characters.
Using backreferences
You use parenthesis to group components of a regular expression into subexpressions. For
example, the regular expression “(ha)+” matches one or more occurrences of the string “ha”.
ColdFusion performs an additional operation when using subexpressions; it automatically saves
the characters in the search string matched by a subexpression for later use within the regular
expression. Referencing the saved subexpression text is called backreferencing.
Character class Matches
:alpha: Any alphabetic character.
:upper: Any uppercase alphabetic character.
:lower: Any lowercase alphabetic character
:digit: Any digit. Same as \d.
:alnum: Any alphanumeric character. Same as \w.
:xdigit: Any hexadecimal digit. Same as [0-9A-Fa-f].
:blank: Space or a tab.
:space: Any whitespace character. Same as \s.
:print: Any alphanumeric, punctuation, or space character.
:punct: Any punctuation character
:graph: Any alphanumeric or punctuation character.
:cntrl: Any character not part of the character classes [:upper:], [:lower:], [:alpha:],
[:digit:], [:punct:], [:graph:], [:print:], or [:xdigit:].
:word: Any alphanumeric character, plus the underscore (_)
:ascii: The ASCII characters, in the Hexadecimal range 0 - 7F