StringReplace
Replaces regex match/es in string. Returns the string after replace was preformed.
javascript · Common Scripts
Source
if ((typeof args.data) !== 'string') { return { Type: entryTypes.error, ContentsFormat: formats.text, Contents: 'Invalid input - please make sure \'data\' is of type string' } } var arr = []; if (args.replaceAll === 'true') { arr.push('g'); } if (args.caseInsensitive === 'true') { arr.push('i'); } if (args.multiLine === 'true') { arr.push('m'); } var newValue = args.newValue === "''" ? "" : args.newValue; var r = new RegExp(args.regex, arr.join('')); var val = args.data.replace(r, newValue); //if no match found - return the original string setContext('StringReplace.Result', val); return { Type: entryTypes.note, Contents: val, ContentsFormat: formats.text };
README
Replaces regex match/es that are found in the string.
This script will return the string after the replacement was performed.
Script Data
| Name | Description |
|---|---|
| Script Type | javascript |
| Tags | Utility |
Inputs
| Argument Name | Description |
|---|---|
| data | The string to perform the replacement on. |
| regex | The regex used to find matches that will be replaced with a new value. |
| newValue | The new value to replace the regex match. Pass ‘’ to remove regex match. |
| replaceAll | Whether to replace matches. Pass true to replace all matches, false to replace only the first occurrence. |
| caseInsensitive | Whether to perform a case-insensitive search and replace. Pass true to perform case-insensitive search and replace, false for case-sensitive. |
| multiLine | Pass true to indicate ‘data’ is a multi-line string, false otherwise. |
Outputs
| Path | Description | Type |
|---|---|---|
| StringReplace.Result | The string after the replacement was performed. | Unknown |