Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 138

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
<cfset IndexOfOccurrence=REFind(" [A-Z]+ ", "Some BIG string")>
<!--- The value of IndexOfOccurrence is 5 --->
The literal characters of the regular expression consist 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 brackets. This character set specifies to
find a single uppercase letter from A to Z, inclusive. The plus sign (+) after the 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
function returns 0 for the regular expression, meaning that it did not find a match.
REFind
You can construct 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 here are fairly basic. For more examples, see
Regular expression syntax
Regular expression syntax has several basic rules and methods.
Using character sets
The pattern within the 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 ".
The regular expression [A-Z][a-z]* matches any word that starts with an uppercase letter and is followed by zero or
more lowercase letters. The special character * after the closing square bracket specifies to match zero or more
occurrences of the character set.
Note: The * only applies to the character set that immediately precedes it, not to the entire regular expression.
A + after the closing square bracket specifies to find one or more occurrences of the character set. You interpret the
regular expression
"[A-Z]+"
expression matches " BIG " and also matches " LARGE ", " HUGE ", " ENORMOUS ", and any other string of
uppercase letters surrounded by spaces.
Considerations when using special characters
Since a regular expression followed by an * can match zero instances of the regular expression, it can also match the
empty string. For example,
<cfoutput>
REReplace("Hello","[T]*","7","ALL") - #REReplace("Hello","[T]*","7","ALL")#<BR>
</cfoutput>
results in the following output:
REReplace("Hello","[T]*","7","ALL") - 7H7e7l7l7o7
as matching one or more uppercase letters enclosed by spaces. Therefore, this regular
Last updated 1/20/2012
"Regular expression
examples" on page 143.
133

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents