Adobe COLDFUSION 9 Manual page 137

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
The next example uses a regular expression to perform the same search. This example searches for the first occurrence
in the search string of any string pattern that consists entirely of uppercase letters enclosed by spaces:
<cfset IndexOfOccurrence=REFind(" [A-Z]+ ", "Some BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->
The regular expression " [A-Z]+ " matches any string pattern consisting of a leading space, followed by any number of
uppercase letters, followed by a trailing space. Therefore, this regular expression matches the string " BIG " and any
string of uppercase letters enclosed in spaces.
By default, the matching of regular expressions is case-sensitive. You can use the
functions for case-insensitive matching.
REReplaceNoCase
Because you often process large amounts of dynamic textual data, regular expressions are invaluable in writing
complex ColdFusion applications.
Using ColdFusion regular expression functions
ColdFusion supplies four functions that work with regular expressions:
REFind
REFindNoCase
REMatch
REMatchNoCase
REReplace
REReplaceNoCase
and
REFind
REFindNoCase
it finds the pattern. For example, the following function returns the index of the first instance of the string " BIG ":
<cfset IndexOfOccurrence=REFind(" BIG ", "Some BIG BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->
To find the next occurrence of the string " BIG ", you must call the
iterating over a search string to find all occurrences of the regular expression, see
on page 141.
and
REReplace
REReplaceNoCase
that matches the regular expression with another string. You can use these functions to replace the first match, or to
replace all matches.
For detailed descriptions of the ColdFusion functions that use regular expressions, see the CFML Reference.
Basic regular expression syntax
The simplest regular expression contains only literal characters. The literal characters must match exactly the text
being searched. For example, you can use the regular expression function
as you can with the
function:
Find
<cfset IndexOfOccurrence=REFind(" BIG ", "Some BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->
In this example,
must match the exact string pattern " BIG ".
REFind
To use the full power of regular expressions, combine literal characters with character sets and special characters, as in
the following example:
use a regular expression to search a string for a pattern and return the string index where
use regular expressions to search through a string and replace the string pattern
Last updated 8/5/2010
REFindNoCase
function a second time. For an example of
REFind
"Returning matched
to find the string pattern " BIG ", just
REFind
132
and
subexpressions"

Advertisement

Table of Contents
loading

Table of Contents