Table.text_replace
text_replacecolumnstermnew_textcase_sensitivityonly_firsterror_on_missing_columns
Group: Text
Aliases: regex, substitute
Documentation
Replaces the first, or all occurrences of term with new_text in each
row of the specified column. If term is empty, the function returns the
table unchanged.
This method follows the exact replacement semantics of the Text.replace
method.
If regex is used the replacement string can contain references to groups
matched. The following syntaxes are supported:
$0: the entire match string $&: the entire match string $n: the nth group
$<foo>: Named group foo For details on Enso's Regex syntax, see
the Help
Documentation.
Arguments
columns: The column(s) to replace values on.term: The term to find. Can beText,Regex, or aColumnof strings.replacement: The text to replace matches with.case_sensitivity: Specifies if the text values should be compared case sensitively.only_first: If True, only replace the first match.error_on_missing_columns: IfTrue, an error is raised if any of the specified columns are not found in the table. IfFalse, missing columns are ignored.
Examples
Replace dashes with underscores.
table.text_replace ["Input"] "-" "_"
Remove leading and trailing spaces from cells.
table.text_replace ["Input"] "^\s*(.*?)\s*$".to_regex "$1"
Replace texts in quotes with parentheses.
table.text_replace ["Input"] '"(.*?)"'.to_regex '($1)'