Adobe COLDFUSION 9 Manual page 139

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
The regular expression [T]* can match empty strings. It first matches the empty string before "H" in "Hello". The
"ALL" argument tells
REReplace
so on, until the empty string before "o" is matched.
This result might be unexpected. The workarounds for these types of problems are specific to each case. In some cases
you can use [T]+, which requires at least one "T", instead of [T]*. Alternatively, you can specify an additional pattern
after [T]*.
In the following examples the regular expression has a "W" at the end:
<cfoutput>
REReplace("Hello World","[T]*W","7","ALL") –
#REReplace("Hello World","[T]*W","7","ALL")#<BR>
</cfoutput>
This expression results in the following more predictable output:
REReplace("Hello World","[T]*W","7","ALL") - Hello 7orld
Finding repeating characters
In some cases, you might want to find a repeating pattern of characters in a search string. For example, the regular
expression "a{2,4}" specifies to match two to four occurrences of "a". Therefore, it would match: "aa", "aaa", "aaaa", but
not "a" or "aaaaa". In the following example, the
<cfset IndexOfOccurrence=REFind("a{2,4}", "hahahaaahaaaahaaaaahhh")>
<!--- The value of IndexOfOccurrence is 6--->
The regular expression "[0-9]{3,}" specifies to match any integer number containing three or more digits: "123",
"45678", and so on. However, this regular expression does not match a one-digit or two-digit number.
You use the following syntax to find repeating characters:
1
m,n
{
}
Where m is 0 or greater and n is greater than or equal to m. Match m through n (inclusive) occurrences.
The expression {0,1} is equivalent to the special character ?.
m
2
{
,}
Where m is 0 or greater. Match at least m occurrences. The syntax
The expression {1,} is equivalent to the special character +, and {0,} is equivalent to *.
m
3
{
}
Where m is 0 or greater. Match exactly m occurrences.
Case sensitivity in regular expressions
ColdFusion supplies case-sensitive and case-insensitive functions for working with regular expressions.
perform case-sensitive matching and
REReplace
matching.
You can build a regular expression that models case-insensitive behavior, even when used with a case-sensitive
function. To make a regular expression case insensitive, substitute individual characters with character sets. For
example, the regular expression [Jj][Aa][Vv][Aa], when used with the case-sensitive functions
matches all of the following string patterns:
• JAVA
to replace all instances of an expression. The empty string before "e" is matched, and
function returns an index of 6:
REFind
REFindNoCase
Last updated 8/5/2010
n
is not allowed.
{,
}
and
perform case-insensitive
REReplaceNoCase
134
and
REFind
or
,
REFind
REReplace

Advertisement

Table of Contents
loading

Table of Contents