Skip to main content

Column.text_replace

text_replaceterm new_textcase_sensitivityonly_first

Group: Text

Documentation

Replaces the first, or all occurrences of term with new_text in each row. If term is empty, the function returns the column 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

  • term: The term to find. Can be Text, Regex, or a Column of 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.

Examples

Replace dashes with underscores.

      column.text_replace "-" "_"

Remove leading and trailing spaces from cells.

      column.text_replace "^\s*(.*?)\s*$".to_regex "$1"

Replace texts in quotes with parentheses.

      column.text_replace '"(.*?)"'.to_regex '($1)'