regsub
Written as regsub(argnum flags):options in a transform expression.
| Minimum arguments | 1 |
| Maximum arguments | 1 |
| Default arguments | 1 |
| Argument modes | SINGLE_PRIMITIVE |
Documentation
Section titled “Documentation”Perform regex substitutions on text with sed-like syntax.
Features:
- Supports sed-style substitution syntax with custom separators
- Case-insensitive matching with ‘i’ flag
- Global replacement with ‘g’ flag
- Automatically handles None values (returns None if input is None)
Syntax: “regsub:{sep}{pattern}{sep}{replacement}{sep}{flags}” Where:
- {sep} is any single character delimiter (commonly / or #)
- {pattern} is the regex pattern to match
- {replacement} is the replacement text
- {flags} optional flags (combinations of ‘i’ and ‘g’)
Flags:
- ‘i’: Case-insensitive matching
- ‘g’: Replace all occurrences (global) instead of just first
Note: The separator character must not appear in the pattern or replacement unless escaped. For complex patterns, choose a separator that doesn’t conflict with your regex syntax.
| Flag | Letter |
|---|---|
| noncaptive_input | I |
Examples
Section titled “Examples”Basic substitution
Section titled “Basic substitution”Input args: ["Hello world"]Transforms: "regsub:/world/planet/"Output: "Hello planet"Global case-insensitive replacement
Section titled “Global case-insensitive replacement”Input args: ["Foo foo FOO"]Transforms: "regsub:#foo#bar#gi"Output: "bar bar bar"Using different separator
Section titled “Using different separator”Input args: ["price=100"]Transforms: "regsub:|price=(\\d+)|cost:\\1|"Output: "cost:100"First occurrence only
Section titled “First occurrence only”Input args: ["a a a a"]Transforms: "regsub:/a/b/"Output: "b a a a"With capture groups
Section titled “With capture groups”Input args: ["2023-01-15"]Transforms: "regsub:#(\\d{4})-(\\d{2})-(\\d{2})#\\3/\\2/\\1#"Output: "15/01/2023"