Rule box category Replace values
Learn how to use rule boxes in the category Replace values to search, compare, and replace values in your attribute in Productsup.
Introduction
The category Replace values contains all rule boxes that can help you search, compare, and replace strings in your attribute values. You can replace text strings and numbers as well as use regular expressions and lists with the rule boxes in this category.
This category can be divided into several subgroups. In the following sections, you can perform the following replacement actions:
Replace static text and translate Google categories
The Replace values rule box category contains the rule boxes to let you replace static values across all products in your attribute's column. The conditions are static and affect all products containing the search value. You can also translate your Google categories from one language to another. You can choose one of the following rule boxes:
Text Replace searches for a term in the attribute and replaces it with a needed value.
Map-Replace searches for several terms in the attribute and replaces whole words, parts of the words, or phrases within a string.
Mapping searches for several terms in the attribute and replaces only the entire string if it matches the search term.
Translate Google Category translates your Google categories from one language to another.
Note
Consider using Lists instead of rule boxes if replacing over 100 terms. See Replace feed terms with the Standard Replacement list.
Text Replace
The Text Replace rule box searches for a term in the attribute and replaces it with a needed value. Use this rule box to replace a term or remove excessive spaces.
Take the steps from Add a rule box to add the Text Replace rule box.
Enter the value you want to replace in the Search for field.
Enter the value you want to have instead of the existing value in the Replace by field. Leave the Replace by field empty if you want to remove your search term. To remove space, see Rule box category Clean up values.
In Case, select whether the matches should be case-sensitive:
Sensitive replaces values only if the case of the value matches in Search for and Replace by.
Insensitive ignores the case of the values during matching.
Select Save.
For example, you have the following values in the description attribute. Your need to replace women with female in all products. You can achieve this by setting up the Text Replace rule box as follows:
description (before) | description (after) |
---|---|
Women's clothes |
|
women clothes |
|
To remove excessive spaces from the string, enter a space in the Search for field and leave the Replace by empty.
description (before) | description (after) |
---|---|
Discount ! |
|
Map-Replace
The Map-Replace rule box lets you replace several different values within a string. The rule box can replace whole words, parts of the words, or phrases within a string.
Take the steps from Add a rule box to add the Map-Replace rule box.
Enter search value into the field. If you have multiple values, start each search value with a new line.
Note
The order of the input values is important. The rule box processes each replacement operation in order from top to bottom. The order change can lead to different results.
Add the delimiter directly after your search term to separate it from the replace value. The rule box selects Colon (:) as a default. But if the colon (:) is a part of the phrase you want to replace, you can use another delimiter. You should choose your delimiter in the List Delimiter drop-down menu.
Enter the replace value directly after the delimiter.
In Case, select whether the matches should be case-sensitive:
Sensitive replaces values only if the case of the search and replace values.
Insensitive ignores the case of the values during matching.
Select Save.
For example, you have the following values in the description attribute. Your need to replace Please note: with Discount! and Today with Only today in all products. You can achieve this by setting up the Map-Replace rule box as follows:
description (before) | description (after) |
---|---|
Please note: Today you get two for the price of one. |
|
There are cases when the order of the search terms is important. For example, if you have values that differ only slightly, such as blue dress and dress, and you need to change them both to female clothes, consider the following order of entering your search terms in the rule box. The longest string should go first.
description (before) | description (after) |
---|---|
blue dress |
|
dress |
|
With the reverse order of the search terms, the result looks as follows:
description (before) | description (after) |
---|---|
blue dress |
|
dress |
|
Mapping
The Mapping rule box lets you replaces only the entire string if it matches the search term.
Take the steps from Add a rule box to add the Mapping rule box.
Enter search value into the field. If you have multiple values, start each search value with a new line.
Add the colon delimiter (:) directly after your search value.
Enter the replace value without spaces after the delimiter.
In Case, select whether the matches should be case-sensitive:
Sensitive replaces values only if the case of the search and replace values.
Insensitive ignores the case of the values during matching.
Select Save.
For example, you have the following values in the description attribute. You need to replace blue with pink. You can achieve this by setting up the Mapping rule box as follows:
description (before) | description (after) |
---|---|
blue |
|
This product is blue. | This product is blue. |
The example shows that This product is blue. stays unchanged as the search term doesn't match the entire string.
Translate Google Category
The Replace values rule box category contains the Translate Google Category rule box to let you translate your Google categories from one language to another.
Google accepts only a predefined list of values in the category attribute.
Tip
You can use a Partner Taxonomy Mapping list to ensure your category attribute contains values accepted by Google. See Replace attributes with Partner Taxonomy Mapping list for more information.
Take the steps from Add a rule box to add the Translate Google Category rule box.
In Source Format, select the current language and country of your Google categories.
Choose id if your category attribute contains category IDs instead of spelled-out category names.
In Target Format, select the language and country you want to translate your Google categories into.
Choose id if you want to transform your spelled-out category names into category IDs.
Tip
You can remove all invalid categories from your category attribute without translating them by selecting the same languages in Source Format and Target Format.
Select Save.
For example, your category attribute contains valid Google categories for the US in English, and you need to translate them into valid Google categories in German.
category (before) | category (after) |
---|---|
Apparel & Accessories > Shoe Accessories > Slippers |
|
Home & Garden > Linens & Bedding > Bedding > Blankets |
|
Apparel & Accessories > Clothing > Underwear & Socks |
|
If you select id in Target Format for the same use case, the rule box outputs the following:
category (before) | category (after) |
---|---|
Apparel & Accessories > Shoe Accessories > Slippers | |
Home & Garden > Linens & Bedding > Bedding > Blankets |
|
Apparel & Accessories > Clothing > Underwear & Socks |
|
Replace dynamic text based on a condition
The Replace values rule box category contains the rule boxes to let you replace dynamic values across all products in your attribute's column. You can choose one of the following rule boxes:
Replace Dynamic Value replaces the current attribute's values with another attribute's values or a static value.
Replace if Column Contains replaces a value if there is a match with a value from another attribute.
Compare Columns assigns a value if data in two attribute columns match.
Replace In Between removes or replaces a value between two other values.
Numeric Compare sets a value by comparing the values in two selected attributes.
Replace Dynamic Value
The Replace Dynamic Value rule box searches the current attribute for the values from the search attribute and replaces them with the values from the replace attribute or a static value.
If the rule box doesn't find the search terms in the current attribute, no changes happen.
Take the steps from Add a rule box to add the Replace Dynamic Values rule box.
In Search Column, choose an attribute where the rule box should take the search values. The attributes listed here and their searched contents come from a previous stage.
In Replace Column, choose the attribute where the rule box takes the replace values. The attributes listed here and their searched contents come from a previous stage.
If you don't want to take values from another attribute, enter a value in the Static Value that should appear in the current attribute.
In Match Type, select the matching logic:
broad lets the rule box search for and replace part of the value, even if it is a part of the word. The matching is case-insensitive.
exact lets the rule box search for and replace values only if the entire words match. The matching is case-insensitive.
Caution
The broad match mode can significantly increase your site processing times. If applicable, we recommend choosing the exact match mode instead.
Select Save.
For example, you need to replace the values in the title attribute that contain data from the gender attribute with the data from the brand attribute. You can achieve this by setting up the Replace Dynamic Value rule box as follows:
gender | brand | title (before) | title (after) |
---|---|---|---|
female | Collection | female dress |
|
male | Collection | male t-shirt |
|
Male | Collection | female dress |
|
When the matching mode is broad, the rule box changes even the matching parts of the words.
Replace if Column Contains
The Replace if Column Contains rule box searches for the search term in another attribute and replaces the values in the current attribute with a replace term, in case of a match.
Take the steps from Add a rule box to add the Replace if Column Contains rule box.
In Column, choose the attribute where the rule box should search for a value. The attributes listed here and their searched contents come from a previous stage.
Enter the values in the following order, separating them with a colon : and following the template
search column:search for replace:replace
:search column is a value to search for in the attribute chosen in Column.
search for replace is a value you want to replace in the current attribute, where you apply the rule box.
replace is a value that should replace the value in the current attribute.
Select Save.
For example, you need to replace Adults in the age_group attribute with Kids if the rule box finds the word small in the size attribute. You can achieve this by setting up the Replace if Column Contains rule box as follows:
size (no changes) | age_group (before) | age_group (after) |
---|---|---|
small | Adults |
|
medium | Adults | Adults |
Compare Columns
The Compare Columns rule box compares values in two selected attributes and modifies the current value if the compared values match.
Take the steps from Add a rule box to add the Compare Columns rule box.
Select attributes you wish to compare in the Column A and Column B drop-down menus. The attributes listed here and their searched contents come from a previous stage.
In Handle match, choose the action type if there is a match between the selected attributes and enter a replace value:
leave unchanged doesn't change the current value.
assign completely overwrites the current value with the set value.
append adds the set value at the end of the current value.
prepend adds the set value at the beginning of the current value.
In Handle no match, choose the action type if there is no match between the selected attributes and enter a replace value:
leave unchanged doesn't change the current value.
assign completely overwrites the current value with the replace value.
append adds the replacement value at the end of the current value.
prepend adds the replace value at the beginning of the current value.
Choose an action if one of the attributes doesn't exist:
treat as empty set an empty value.
leave unchanged doesn't change the current value.
Select Save.
Note
The matching is case-sensitive, and the values should match completely.
For example, you want to assign 50 EUR
to the price attribute if the values in title and brand match. You can achieve this by setting up the Compare Column rule box as follows:
brand | title | price (before) | price (after) |
---|---|---|---|
MyBrand | MyBrand | 100 EUR |
|
Brand | MyBrand | 90 EUR | 90 EUR |
MyBrand | MyBrand dresses | 89 EUR | 89 EUR |
|
In this example, only the values of the first row match completely, and the rule box replaces the value in price with 50 EUR
. The values from the other two rows don't entirely match, and the rule box leaves them unchanged as per the settings.
Also, if both values in the attributes are empty, the rule box considers this a match and sets the value according to your settings.
Text Replace if Column Contains
The Text Replace if Column Contains rule box searches for a term in the selected attribute and, if it finds it, replaces the value in the current attribute with a replacement value. This rule box works similarly to the Map-Replace rule box but also lets you set a condition for replacement.
Take the steps from Add a rule box to add the Text Replace if Column Contains rule box.
In Source Column, select an attribute where the rule box should search for a value. The attributes listed here and their searched contents come from a previous stage.
Select the matching logic:
equals lets the rule box search for and replace value only if the entire string matches. The matching is case-insensitive.
contains lets the rule box search for and replace value if part of the string matches. The matching is case-insensitive.
In the search field, enter the term you want to replace in the current attribute. The matching is case-sensitive.
In the replace field, enter the term you want to set instead of the existing term in the current attribute.
Select Save.
For example, you want to replace female with lady in the gender attribute if the rule box finds women in the description attribute. You can achieve this by setting up the Text Replace if Column Contains rule box as follows:
description | gender (before) | gender (after) |
---|---|---|
Women's little black dress | female |
|
Blue trousers | female | female |
Women's white t-shirt | Female | Female |
The example shows that description should contain an exact match to the search term but can have different capitalization. The second condition is that the term from the search field should exactly match the term in the current attribute, and it considers capitalization.
Replace In Between
The Replace In Between rule box removes or replaces a value between two other values.
Take the steps from Add a rule box to add the Replace In Between rule box.
Enter the values that frame the term you want to replace in From and To. The rule box replaces the entire phrase, including the entered values.
Add a replace value into the Replace With field. You can enter spaces or punctuation marks before and after the term to separate it from the rest of the words in the string.
Select Save.
For example, you need to replace all description values within the quotation marks with another value. You can achieve this by setting up the Replace In Between rule box as follows:
description (before) | description (after) |
---|---|
"white" dress |
|
"little black" dress |
|
If you enter new
in Replace With without the quotes, the platform changes both values to new dress
.
Numeric Compare
The Numeric Compare rule box compares numeric values in two selected attributes and overwrites the values in the current attribute with a set value. The rule box can only handle numeric values without text or currency symbols.
Take the steps from Add a rule box to add the Numeric Compare rule box.
In the first and second Select Option drop-down menus, select the attributes that you want to compare and select the comparison operator between them:
> means that the first value is bigger than the second.
< means that the first value is less than the second.
>= means that the first value is bigger or equal to the second.
<= means that the first value is less or equal to the second.
== means that the first value is equal to the second.
!= means that the first value isn't equal to the second.
The attributes listed here and their searched contents come from a previous stage.
In the handle match field, enter the value you want to assign when the attribute finds a match for the comparison of two values from the selected attributes.
In the handle no match field, enter the value you want to set instead of the values in the current attribute if there is no match for the comparison of two values of the selected attributes. You can choose how to set the value:
leave unchanged doesn't change the current value.
assign completely overwrites the current value with the set value.
append adds the set value at the end of the current value.
prepend adds the set value at the beginning of the current value.
Select Save.
For example, you need to replace all values in the description attribute with Sale!
if the values in price are less or equal (<=) to the values in sale_price. You can achieve this by setting up the Numeric Compare rule box as follows:
price | sale_price | description (before) | description (after) |
---|---|---|---|
70.00 | 99.00 | Black dress |
|
150.00 | 99.00 | Blue dress | Blue dress |
Convert special characters and code
The Replace values rule box category contains the rule boxes to let you convert special characters and encoding:
Convert Special Characters changes special characters into letters.
Convert Character Encoding converts your data from one encoding into another.
Remove UTF-8 Control Characters removes the hidden UTF-8 control characters.
Convert Special Characters
The Convert Special Characters rule box changes special characters to Latin letters, such as € to EUR, Ü to UE, ß to ss, and so on.
Take the steps from Add a rule box to add the Convert Special Characters rule box.
Select Save.
For example, you have the € sign in the price attribute, and your export channel requires receiving all prices in the format EUR. You can achieve this with the Convert Special Characters rule box:
price (before) | price (after) |
---|---|
7 € |
|
12€ |
|
The example shows that the rule box changes the special character even if there is no space between it and the rest of the text.
Convert Character Encoding
The Convert Character Encoding rule box changes your encoded data into a different encoding. It can convert UTF-8, Windows-1251, and Windows-1252 characters into ASCII, US-ASCII, UTF-8, ISO-8859-1, Windows-1251, and Windows-1252.
Take the steps from Add a rule box to add the Convert Character Encoding rule box.
Select the encoding of your data in the Source Encoding drop-down menu:
UTF-8
Windows-1251
Windows-1252
Select the encoding of your data in the Target Encoding drop-down menu:
UTF-8
ASCII
US-ASCII
ISO-8859-1
Windows-1251
Windows-1252
In Additional Options, select what the rule box should do in case it can't find the corresponding representation to the character in the target encoding:
TRANSLIT lets the rule box find a similar character in the target encoding.
IGNORE lets the rule box discard the character.
TRANSLIT & IGNORE performs both TRANSLIT and IGNORE, whichever is more appropriate.
Select Save.
Remove UTF-8 Control Characters
The Remove UTF-8 Control Characters rule box removes hidden UTF-8 control characters, such as \xc2\x80
, and replaces them with space or nothing.
Sometime the import or export may fail because you data contains invisible characters. See UTF-8 encoding table and Unicode characters for a list of them. Invisible Unicode characters don't have a visual representation. You can't see them, however they affect your data. To check if your value contains invisible characters, such as <0x9X>, use a text editor or this tool.
You can remove them with the Remove UTF-8 Control Characters rule box.
Take the steps from Add a rule box to add the Remove UTF-8 Control Characters rule box.
In the Replace with, select what you want to get instead of the value:
White space sets the space instead of the removed code.
No space doesn't set anything instead of the removed code.
Select Save.
Create text template using data from other attributes
The Replace values rule box category contains the rule boxes that let you insert values from several attributes into the text of the selected attribute. You can choose one of the following rule boxes:
Text Template adds the values dynamically with the help of Twig.
Text Template With List adds the values dynamically with the help of Twig and a list created in Lists.
Text Template
The Text Template rule box adds the values dynamically with the help of Twig. Twig is a template engine based on PHP that lets you add dynamic content to the template.
See Twig-based rule box capabilities to enhance your product data for use cases and rules on how to create Twig codes.
The Text Template rule box functions similarly to the Append/Prepend Column rule box but lets you link values from several attributes together with static placeholder text.
Take the steps from Add a rule box to add the Text Template rule box.
Enter your text template in the input field.
To add a dynamic value, enter the exact name of the attribute between two curly brackets and spaces at the beginning and end of the value, such as
{{ attribute_name }}
.The rule box uses the attributes and their contents from a previous stage. If the chosen attributes have any changes in their values in the same stage where you apply the rule box, the platform still uses the unchanged values as they come from a previous stage.
Tip
Select the >_ icon in a rule box to get AI-based suggestions for Twig codes.
To create the most accurate prompts, see our best practices in Create the right prompt for the AI Twig generator.
Select Save.
For example, you need to create product descriptions in the description attribute from your product_type and brand attributes. You can achieve this with the Text Template rule box by entering this Twig-based text template in the input field: This is a {{ product_type }} by {{ brand }}.
.
product_type (no changes) | brand (no changes) | description (before) | description (after) |
---|---|---|---|
T-shirt | Nike |
| |
Training bra | Puma | Purple training bra |
|
Adidas | Adidas shorts |
|
Text Template With List
The Text Template With List rule box applies a text template using Twig and values taken from a list created in Lists. See Lists feature for more information on lists.
Go to Lists from your site's main menu and add all terms you need to replace to the Standard, Dynamic, or Attribute-based Replacement list. See Replacement lists to choose a required type.
Take the steps from Add a rule box to add the Text Template With List rule box.
Select use list to choose a list that contains the values you want to use in the text template.
Enter your text template in the input field.
To add a dynamic value, enter the exact name of the attribute between two curly brackets and spaces at the beginning and end of the value, such as
{{ attribute_name }}
.The rule box uses the attributes and their contents from a previous stage. If the chosen attributes have any changes in their values in the same stage where you apply the rule box, the platform still uses the unchanged values as they come from a previous stage.
To refer to the values of the selected list and add them all separated with a comma and a space character (, ), use the following Twig:
{{ ListValues | join(', ') }}
.Tip
Select the >_ icon in a rule box to get AI-based suggestions for Twig codes.
To create the most accurate prompts, see our best practices in Create the right prompt for the AI Twig generator.
Select Save.
For example, you have created the following list called colors and added all available product colors to it:
You need to create product descriptions in the description attribute using the values from the title attribute and the replace terms added to the list. You can achieve this with the following setup of the Text Template With List rule box:
title (no changes) | description (before) | description (after) |
---|---|---|
T-shirt |
| |
Training bra | Black training bra |
|
Adidas shorts |
|
Replace values with list-based rule boxes
The Replace values rule box category contains the replacement rule boxes to let you replace a large number of values in your data, adding them to a replacement list that you can apply to the following rule boxes. The rule boxes search for the list terms in the attribute's column and replace matching values in bulk:
Replacement applies a replacement list to substitute the matching complete words in the string with the mapped terms from the list.
Replacement Sensitive applies a replacement list to substitute the matching parts of the word, a complete word within a string, or an entire string with the terms from the list.
Taxonomy Mapping applies a replacement list to substitute the entire string or only a part of the string with the terms from the list. This rule box works best if you need to replace the category terms.
See Rule box category Use lists to set up the rule boxes.
Replace values using regular expressions
The Replace values rule box category contains the rule boxes that let you use regular expressions to replace certain values.
A regular expression (regex) is a sequence of characters that uses specific syntax or structure rules to define a search pattern. Using a regex, you can search your data for specific text pattern matches instead of exact text matches.
You can choose one of the following rule boxes:
Preg Match scans the attribute for matches to the regex specified in the rule box until it finds the first match in a string. Then, it preserves the matching part and removes the rest of the string.
Preg Match All scans the attribute for matches to the regex specified in the rule box to find all matches within the entire string, while the Preg Match rule box stops scanning a value after the first match.
Preg Replace scans the attribute for matches to the regex specified in the rule box and replace all the matching values with a static value of your choice.
See Rule box category Use regular expressions to set up the rule boxes.