Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 140

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
• java
• Java
• jAva
• All other combinations of case
Using subexpressions
Parentheses group parts of regular expressions into subexpressions that you can treat as a single unit. For example, the
regular expression "ha" specifies to match a single occurrence of the string. The regular expression "(ha)+" matches one
or more instances of "ha".
In the following example, you use the regular expression "B(ha)+" to match the letter "B" followed by one or more
occurrences of the string "ha":
<cfset IndexOfOccurrence=REFind("B(ha)+", "hahaBhahahaha")>
<!--- The value of IndexOfOccurrence is 5 --->
You can use the special character | in a subexpression to create a logical "OR". You can use the following regular
expression to search for the word "jelly" or "jellies":
<cfset IndexOfOccurrence=REFind("jell(y|ies)", "I like peanut butter and jelly">
<!--- The value of IndexOfOccurrence is 26--->
Using special characters
Regular expressions define the following list of special characters:
+ * ? . [ ^ $ ( ) { | \
In some cases, you use a special character as a literal character. For example, if you want to search for the plus sign in
a string, you have to escape the plus sign by preceding it with a backslash:
"\+"
The following table describes the special characters for regular expressions:
Special Character
Description
\
A backslash followed by any special character matches the literal character itself, that is, the backslash escapes the
special character.
For example, "\+" matches the plus sign, and "\\" matches a backslash.
.
A period matches any character, including newline.
To match any character except a newline, use [^#chr(13)##chr(10)#], which excludes the ASCII carriage return and
line feed codes. The corresponding escape codes are \r and \n.
[ ]
A one-character character set that matches any of the characters in that set.
For example, "[akm]" matches an "a", "k", or "m". A hyphen in a character set indicates a range of characters; for
example, [a-z] matches any single lowercase letter.
If the first character of a character set is the caret (^), the regular expression matches any character except those
in the set. It does not match the empty string.
For example, [^akm] matches any character except "a", "k", or "m". The caret loses its special meaning if it is not
the first character of the set.
Last updated 1/20/2012
135

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents