REReplace

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

Argument Reference for the REReplace function

string

Required: Yes
A string or a variable that contains one

regex

Required: Yes
Regular expression to replace.

substring

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

scope

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

Links more information about REReplace

Examples sample code invoking the REReplace function


Strip Characters Using reReplace

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

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

Expected Result: test123


Extract Characters Using Back Reference

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


Fork me on GitHub