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 Parameter | Type | Description |
---|---|---|
input | string | The input string. |
pattern | string | The regex pattern string to replace. (Ex: '\d{2}') |
replacement | string | The match replacement. |
flags (optional) | string | he modfier string. (Ex: combination of g, i, m) |
Return value
Type |
---|
string |
Sample
Example | Result | Description |
---|---|---|
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
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article