Skip to main content

DB_Table.text_replace

text_replacecolumnsterm new_text case_sensitivityonly_first

Group: Text

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 Text.replace. 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 The exact syntax of the regular expression is dependent on the database engine.

Arguments

  • columns: Specifies columns by a name, index or regular expression to match names, or a Vector of these.
  • 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.

      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)'