Regex Replace
Synopsis
A text processing processor that finds and replaces text patterns using regular expressions, 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 |
disabled | N | false | When true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration |
Details
The processor uses regular expressions to find and replace text patterns within string fields. It supports both simple text replacement and pattern matching with capture groups, which the replacement refers to as $1, $2 or ${name}.
This processor is an alias for the gsub processor, providing the same functionality with a more descriptive name.
Regular expression patterns support 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.
Regular Expression Semantics
Patterns use RE2 syntax, with lookahead ((?=…), (?!…)) and lookbehind ((?<=…), (?<!…)) added. Backreferences (\1, \k<name>), atomic groups and possessive quantifiers are not supported: a pattern that uses one fails to compile, and the processor fails the record — its on_failure processors run, and ignore_failure applies. A lookbehind cannot contain a capture group or another lookaround. \d, \w and \s match ASCII characters.
Matching has no per-match timeout, because none is needed: no pattern can make matching backtrack without bound.
Matching is unanchored and case-sensitive. A plain string matches anywhere in the field — anchor with ^ and $, and prefix the expression with (?i) for case-insensitive matching.
A pattern is rejected before it compiles when it:
- exceeds 1000 characters,
- uses more than 100 quantifiers (
*,+,{n,m}), - nests groups more than 10 levels deep, or
- takes longer than 100ms to compile.
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: | |