replace
Replaces occurrences of a substring within a string with another substring.
Syntax
replace(source, old, new)
replace(source, old, new, max_replacements)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| source | string | Yes | The original string where replacements will be made. |
| old | string | Yes | The substring to search for and replace. |
| new | string | Yes | The replacement substring. |
| max_replacements | integer | Optional | The maximum number of replacements to perform. Defaults to -1, which replaces all occurrences. |
Returns
Type: string
The modified string with the specified replacements applied.
Examples
Replace all occurrences:
replace([description], "old system", "new system")
If description is "Migrate from old system to old system backup", the result is "Migrate from new system to new system backup".
Replace only the first occurrence:
replace("apple, apple, apple", "apple", "orange", 1)
Result: "orange, apple, apple".
Remove a substring by replacing with empty string:
replace([notes], "\n", "")
Removes all newline characters from the notes field.
Notes
- The search is case-sensitive. Use
regex_replacewith the(?i)flag if you need case-insensitive replacement. - When
max_replacementsis set to-1(the default), all occurrences are replaced. - If the
oldsubstring is not found, the original string is returned unchanged.
Comments
0 comments
Please sign in to leave a comment.