StringReplace
Alias:StringReplace
, RegexReplace
Output:StringStream
Replace every regex match in the string with the result of a particular function
Parameter | Type | Required | Position | Default Value | Summary |
---|---|---|---|---|---|
String In | string | ✔ | 1 | The string to match | |
Pattern Find | string | ✔ | 2 | The regular expression pattern. Uses the .net flavor | |
Replace | string | 3 | Either this or 'Function' must be set. | The replacement string. Use $1, $2 etc. to replace matched groups | |
Function | string | Either this or 'Replace' must be set. | A function to take the regex match and return the new string | ||
IgnoreCase | bool | False | Whether the regex should ignore case. |
Examples​
Example 1​
Basic Replacement
SCL​
StringReplace String: 'number 1' Find: '1' Replace: 'one'
Expected Output​
number one
Example 2​
Replace using a function
SCL​
StringReplace 'number 1' '\w+' Function: (stringToCase <> TextCase.Upper)
Expected Output​
NUMBER 1
Example 3​
Replace captured groups
SCL​
StringReplace 'number 13' '(\w+)\s+(\d+)' '$2 was your $1'
Expected Output​
13 was your number