--- layout: default title: Substitute string parent: Processors grand_parent: Pipelines nav_order: 370 --- # Substitute string processor The `substitute_string` processor matches a key's value against a regular expression and replaces all matches with a replacement string. ## Configuration The following table describes the options you can use to configure the `substitute_string` processor. Option | Required | Type | Description :--- | :--- | :--- | :--- `entries` | Yes | List | List of entries. Valid values are `source`, `from`, `to`, and `substitute_when`. `source` | N/A | N/A | The key to modify. `from` | N/A | N/A | The Regex String to be replaced. Special regex characters such as `[` and `]` must be escaped using `\\` when using double quotes and `\ ` when using single quotes. See [Java Patterns](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/regex/Pattern.html) for more information. `to` | N/A | N/A | The String to be substituted for each match of `from`. `substitute_when` | No | String | A [conditional expression]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/expression-syntax/), such as `/env == "prod"`, that determines whether the entry is applied to the event. By default, the entry is applied to all events. ### Usage To get started, create the following `pipeline.yaml` file: ```yaml pipeline: source: file: path: "/full/path/to/logs_json.log" record_type: "event" format: "json" processor: - substitute_string: entries: - source: "message" from: ":" to: "-" sink: - stdout: ``` {% include copy.html %} Next, create a log file named `logs_json.log`. After that, replace the `path` of the file source in your `pipeline.yaml` file with your file path. For more detailed information, see [Running Data Prepper]({{site.url}}{{site.baseurl}}/data-prepper/getting-started/running/). Before you run Data Prepper, the source appears in the following format: ```json {"message": "ab:cd:ab:cd"} ``` After you run Data Prepper, the source is converted to the following format: ```json {"message": "ab-cd-ab-cd"} ``` `from` defines which string is replaced, and `to` defines the string that replaces the `from` string. In the preceding example, string `ab:cd:ab:cd` becomes `ab-cd-ab-cd`. If the `from` regex string does not return a match, the key is returned without any changes.