Regex Replace
Synopsis
A text processing processor that finds and replaces text patterns using regular expressions, providing powerful pattern-based text transformation capabilities for data cleaning, formatting, and normalization.
Schema
- regex_replace:
field: <ident>
regex: <string>
replacement: <string>
target_field: <ident>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
Configuration
The following fields are used to define the processor:
Field | Required | Default | Description |
---|---|---|---|
field | Y | - | Field containing the text to process |
regex | Y | - | Regular expression pattern to match |
replacement | Y | - | Replacement text or pattern |
target_field | N | field | Field to store the modified text |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue if regex processing fails |
ignore_missing | N | false | Continue if source field doesn't exist |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
Details
The processor uses regular expressions to find and replace text patterns within string fields. It supports both simple text replacement and complex pattern matching with capture groups and backreferences.
This processor is an alias for the gsub
processor, providing the same functionality with a more descriptive name.
Regular expression patterns support full regex syntax including character classes, quantifiers, anchors, and grouping. The replacement string can include backreferences ($1, $2, etc.) to captured groups from the regex pattern.
The processor handles all occurrences of the pattern within the text, making it suitable for comprehensive text cleaning and transformation tasks.
Test regex patterns thoroughly to avoid unintended matches or performance issues with complex patterns.
Examples
Basic Text Replacement
Replacing simple text patterns... |
|
updates the error level: |
|
Pattern Matching with Capture Groups
Using capture groups for reformatting... |
|
reformats the date: |
|
Email Masking
Masking email addresses for privacy... |
|
masks the username portion: |
|
Log Level Normalization
Normalizing various log level formats... |
|
standardizes log levels: |
|
URL Path Extraction
Extracting paths from URLs... |
|
extracts just the path: |
|
Multi-Pattern Replacement
Applying multiple regex replacements... |
|
sanitizes sensitive information: |
|