Skip to main content
Version: 1.3.0

Replace

Mutate String Manipulation

Synopsis​

Performs string replacement operations with case-sensitive and case-insensitive options.

Schema​

- replace:
field: <ident>
pattern: <string>
replacement: <string>
target_field: <string>
replace_all: <boolean>
case_sensitive: <boolean>
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:

FieldRequiredDefaultDescription
fieldY-Source field containing string to process
patternY-String pattern to search for
replacementY-String to replace matched pattern with
target_fieldNSame as fieldTarget field to store result
replace_allNtrueReplace all occurrences (false = replace first only)
case_sensitiveNtrueCase-sensitive pattern matching
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if replacement fails
ignore_missingNfalseSkip processing if referenced field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier

Details​

Performs literal string replacement operations with flexible matching options. The processor supports both case-sensitive and case-insensitive matching with options to replace all occurrences or just the first match.

The processor supports template substitution in the pattern field, allowing dynamic pattern matching based on other field values. The replacement string is used literally without template processing.

note

This processor performs literal string matching, not regular expression matching. For pattern-based replacements with wildcards or regex patterns, use the regex-replace processor instead.

When case_sensitive is disabled, the processor performs case-insensitive matching while preserving the original case of surrounding text. Only the matched portion is replaced.

warning

If the pattern is an empty string, the processor skips replacement to prevent infinite loops or unexpected behavior. Set the pattern to a meaningful search string.

Examples​

Basic String Replacement​

Replacing environment names in configuration...

{
"config_path": "/app/config/dev/settings.yaml"
}
- replace:
field: config_path
pattern: "/dev/"
replacement: "/prod/"
target_field: prod_config_path

updates path for production:

{
"config_path": "/app/config/dev/settings.yaml",
"prod_config_path": "/app/config/prod/settings.yaml"
}

Case-Insensitive Replacement​

Replacing text regardless of case...

{
"log_message": "ERROR: Database connection failed. Error details: connection timeout"
}
- replace:
field: log_message
pattern: "error"
replacement: "issue"
case_sensitive: false
target_field: cleaned_message

replaces all case variations:

{
"log_message": "ERROR: Database connection failed. Error details: connection timeout",
"cleaned_message": "issue: Database connection failed. issue details: connection timeout"
}

First Occurrence Only​

Replacing only the first match...

{
"filename": "log_2024_01_15_log_backup.txt"
}
- replace:
field: filename
pattern: "log"
replacement: "archive"
replace_all: false
target_field: archive_name

replaces first occurrence only:

{
"filename": "log_2024_01_15_log_backup.txt",
"archive_name": "archive_2024_01_15_log_backup.txt"
}

URL Path Modification​

Updating API version in URLs...

{
"api_endpoint": "https://api.example.com/v1/users/profile"
}
- replace:
field: api_endpoint
pattern: "/v1/"
replacement: "/v2/"
target_field: updated_endpoint

updates API version:

{
"api_endpoint": "https://api.example.com/v1/users/profile",
"updated_endpoint": "https://api.example.com/v2/users/profile"
}

Sensitive Data Masking​

Replacing sensitive information with placeholders...

{
"sql_query": "SELECT * FROM users WHERE password='secret123' AND token='abc-xyz-789'"
}
- replace:
field: sql_query
pattern: "secret123"
replacement: "***MASKED***"
target_field: safe_query

masks sensitive values:

{
"sql_query": "SELECT * FROM users WHERE password='secret123' AND token='abc-xyz-789'",
"safe_query": "SELECT * FROM users WHERE password='***MASKED***' AND token='abc-xyz-789'"
}

Hostname Standardization​

Standardizing hostname formats...

{
"server_list": "web01.local,web02.local,web03.local"
}
- replace:
field: server_list
pattern: ".local"
replacement: ".prod.company.com"
target_field: production_servers

updates all domain suffixes:

{
"server_list": "web01.local,web02.local,web03.local",
"production_servers": "web01.prod.company.com,web02.prod.company.com,web03.prod.company.com"
}

Template Pattern Replacement​

Using dynamic pattern from another field...

{
"old_username": "john_temp",
"message": "User john_temp logged in successfully. Welcome john_temp!"
}
- replace:
field: message
pattern: "{{{old_username}}}"
replacement: "john_doe"
target_field: updated_message

replaces using field value as pattern:

{
"old_username": "john_temp",
"message": "User john_temp logged in successfully. Welcome john_temp!",
"updated_message": "User john_doe logged in successfully. Welcome john_doe!"
}

Empty Pattern Handling​

Handling empty pattern gracefully...

{
"text": "Sample text for processing"
}
- replace:
field: text
pattern: ""
replacement: "replacement"
target_field: result

skips replacement with empty pattern:

{
"text": "Sample text for processing",
"result": "Sample text for processing"
}