Uses a regular expression (RE) to search a string for a string pattern and replace it with another. The search is case-sensitive.
If the scope
attribute is set to one
, returns a string with the first occurrence of the regular expression replaced by the value of substring.
If the scope
attribute is set to all
, returns a string with all occurrences of the regular expression replaced by the value of substring.
If the function finds no matches, it returns a copy of the string unchanged.
REReplace(string, reg_expression, substring [, scope ])
REFind,
Replace,
ReplaceList,
REReplaceNoCase
New in ColdFusion MX: this function supports the following special codes in a substring, to control case conversion:
As in ColdFusion 5, the characters \1, \2, and so on, are backreference codes. To include these literal characters in a substring, you must escape them, by inserting a backslash before them (for example, change "\u" to "\\u").
To include a backslash followed by a backreference or case conversion code, you must escape the backslash, by prefixing another backslash (for example, "\\\1").
For more information on new features, see REFind.
For more information, see Developing ColdFusion MX Applications with CFML.
<p>The REReplace function returns <i>string</i> with a regular expression replaced with <i>substring</i> in the specified scope. Case-sensitive search. <p>REReplace("CABARET","C|B","G","ALL"): <cfoutput>#REReplace("CABARET","C|B","G","ALL")#</cfoutput> <p>REReplace("CABARET","[A-Z]","G","ALL"): <cfoutput>#REReplace("CABARET","[A-Z]","G","ALL")#</cfoutput> <p>REReplace("I love jellies","jell(y|ies)","cookies"): <cfoutput>#REReplace("I love jellies","jell(y|ies)","cookies")# </cfoutput> <p>REReplace("I love jelly","jell(y|ies)","cookies"): <cfoutput>#REReplace("I love jelly","jell(y|ies)","cookies")#</cfoutput>