Uses a regular expression (regex) to search a string for a string pattern and replace it with another. The search is case-sensitive.

reReplace(string, regex, substring [, scope]) → returns string

Member Function Syntax

string.reReplace(regex, substring[, scope])

Argument Reference

string string

A string or a variable that contains one

regex string

Regular expression to replace.

substring string

A string or a variable that contains one. Replaces substring with the regex match

scope string
Default: one

* one: Replace the first occurrence of the regular
expression. Default.
* all: Replace all occurrences of the regular expression.
  • one
  • all

Links more information about reReplace

Sample code invoking the reReplace function

This example strips out all characters except a-z and 0-9.

reReplace("test 123!", "[^a-z0-9]", "", "ALL")

Expected Result: test123

Uses a back reference: \1 to extract the pattern contained within the parenthesis.

reReplace("123abc456", "[0-9]+([a-z]+)[0-9]+", "\1")

Expected Result: abc

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub