////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////
:documentationPath: /pipeline/transforms/
:language: en_US
:description: The Replace In String transform performs simple search and replace operations on String fields.

:openvar: {
:closevar: }

= image:transforms/icons/replaceinstring.svg[Replace in String transform Icon, role="image-doc-icon"] Replace in String

[%noheader,cols="3a,1a", role="table-no-borders" ]
|===
|
== Description

The Replace In String transform performs simple search and replace operations on String fields.

It also supports regular expressions and group references. group references are picked up in the replace by string as $n where n is the number of the group.

You can also use xref::variables.adoc#_hexadecimal_values[hexadecimal replacements] for special characters

|
== Supported Engines
[%noheader,cols="2,1a",frame=none, role="table-supported-engines"]
!===
!Hop Engine! image:check_mark.svg[Supported, 24]
!Spark! image:check_mark.svg[Supported, 24]
!Flink! image:check_mark.svg[Supported, 24]
!Dataflow! image:check_mark.svg[Supported, 24]
!===
|===

== Options

[options="header"]
|===
|Option|Description
|Transform name|Name of the transform. This must be unique within a plugin.
|In stream field|The field in which a replacement has to take place.
|Out stream field|The result field. If you leave the Out stream field empty, it will replace the value in the In stream field. Otherwise, the replacement value is output in a new field.
|use RegEx|Specify whether a regular expression is used for specifying the value to replace. This value must be Y or N.
|Search|Search for a certain pattern. You can use a wildcard (*) for matching multiple characters. If you are using a regular expression, specify the pattern in this field.
|Replace with|Specify the value to replace the search pattern with. If you are using egular expressions, specify the replacement part of the string here.
|Set empty string?|Specify whether the field value is replaced with a blank string. This value must be Y or N.
|Replace with field|Replace the search pattern with the vlaue from the field you specify.
|Whole word|Specify whether the whole word must match the search pattern to be replaced. This value must be Y or N.
|Case sensitive|Specify whether the search is case sensitive. This value must be Y or N.
|Is Unicode|Specify whether the search uses unicode encoding. This value must be Y or N.
|===

== Example

You could parse out sections of a string as follows

* regex = ^([0-9]{openvar}4{closevar})([0-9]{openvar}7{closevar})$
* replace with = $2

This will replace any 11 digit numbers with the last 7 digits.
