regexReplace

Modified on Wed, 02 Aug 2023

Description

Replace matches for `pattern` in `input` string with `replacement`.

Syntax

regexReplace(input, pattern, replacement, flags)

Parameters

Input ParameterTypeDescription
inputstringThe input string.
patternstringThe regex pattern string to replace. (Ex: '\d{2}')
replacementstringThe match replacement.
flags (optional)stringhe modfier string. (Ex: combination of g, i, m)

Return value

Type
string

Sample

ExampleResultDescription
regexReplace('Hi Fred', 'Fred', 'Barney')'Hi Barney'Replace with new string
regexReplace('Hi! how are you', 'o', '__')'Hi! h__w are you'Replace first matched substring
regexReplace('Hi! how are you', 'o', '__', 'gi' )'Hi! h__w are y__u'Ignore case and replace all matched substrings
regexReplace('Date : 12-01-1990', '\d{2}', 'xx');'Date : xx-01-1990'Replace first two digit characters with 'xx'
regexReplace('Date : 12-01-1990', '\d{2}', 'xx', 'g');'Date : xx-xx-xxxx'Replace all two digit characters with 'xx'

To view all the String functions, click here.

See Also