Rule: Find and Replace#
This rule finds text within an element’s content and replaces it with another.
Extra features#
- Case sensitivity
- Regular expression support
- Text, variables, and empty values can be used in the fields
- Option to add multiple rows
- Row order matters - rules are applied from top to bottom
Practical examples#
Example 1: Remove information from an element#
Remove information from an element – promotional texts or dimensions from product names, links from product descriptions, unwanted texts or HTML characters from descriptions
1. Creating a new rule:
- Open the “Rules” page.
- Click the New rule button.
2. Selecting the rule type:
- In the Rule type field, select the Find and Replace option.
3. Selecting products:
- In the Query field, choose either All products or create your own Product query for specific products you want the rule to apply to.
4. Choosing the element to change:
- In the Element field, select the element you want to modify.
- In this case, you can choose the element:
product descriptionorproduct name
- In this case, you can choose the element:
5. Configuring additional options:
- If you need to distinguish between uppercase and lowercase, check the option “Case sensitive”.
- If you want to use regular expressions for searching, check the option “Regular expressions”.
6. Enter the search text:
- In the Find field, enter the text to search for, a regular expression, or use the value of another element via a variable (e.g.,
%size%). - In our example, these could be:
saleXXLwww.my_eshop.com/accessories<H1>
- 💡 Tip: The rule allows you to add multiple rows (and therefore multiple find and replace conditions). Row order matters because Mergado evaluates the rows from top to bottom sequentially.
7. Enter the replacement text:
- Leave the Replace field empty. This way, Mergado will remove all found occurrences of the text – replacing them with an empty value.
8. Naming the rule:
- In the last step, enter the rule name, for example Remove promo texts from names or Clean up product descriptions.
Example 2: Edit texts in elements#
Edit texts in elements – replace, supplement, or change format.
1. Creating a new rule:
- Open the “Rules” page.
- Click the New rule button.
2. Selecting the rule type:
- In the Rule type field, select the Find and Replace option.
3. Selecting products:
- In the Query field, choose either All products or create your own Product query for specific products you want the rule to apply to.
- 💡 Tip: This rule is unique in that even when using the All products query, it does not throw an error if the search term is not found in a particular product.
4. Choosing the element to change:
- In the Element field, select the element you want to modify.
5. Configuring additional options:
- If you need to distinguish between uppercase and lowercase, check the option Case sensitive.
- If you want to use regular expressions for searching or replacing, check the option Regular expressions.
6. Enter the search text:
- In the Find field, enter the text you want to replace, a regular expression, or use the value of another element via a variable (e.g., %size%).
- In our example, you can use:
couchCZKSummer campaign/
7. Enter the replacement text:
- In the “Replace” field, enter the new text, a regular expression, or use the value of another element via a variable (e.g.,
%size%). - In our example, this could be:
sofaEURBack to school>
- 💡 Tip: You can combine multiple “Find and Replace” rules for different purposes – e.g., one for currency, another for campaign names.
8. Naming the rule:
- In the last step, enter the rule name of your choice, for example Edit product names or Change currency format.
Example 3: Swap information within a single element#
Swap information within a single element – move the first paragraph after the second in a product description
1. Creating a new rule:
- Open the “Rules” page.
- Click the New rule button.
2. Selecting the rule type:
- In the Rule type field, select the Find and Replace option.
3. Selecting products:
- In the Query field, choose either All products or create your own Product query for specific products you want the rule to apply to.
4. Choosing the element to change:
- In the Element field, select the element you want to modify.
5. Configuring additional options:
- If you need to distinguish between uppercase and lowercase, check the option Case sensitive.
- Check the option Regular expressions so you can use them in the search.
6. Enter the search text:
- In the Find field, enter the following regular expression:
^(.*?)\n\n(.*)$ - This regular expression splits the text into the first and second paragraphs, separated by an empty line
(\n\n)
7. Enter the replacement text:
- In the Replace field, enter the following value:
-
\2\1
-
8. Naming the rule:
- In the last step, enter the rule name of your choice, for example Swap information within a single element.
FAQ#
What is the Find and Replace rule for?#
This rule allows you to find specific text in an element’s content and replace it with another text, variable, or empty value. You can use it for editing, supplementing, or removing text in names, descriptions, categories, and other elements.
Can I use this rule to remove text, links, or HTML tags from a product description?#
Yes. In the “Find” field, paste the text or HTML element you want to remove (e.g., <H1> or www.my_eshop.com). Leave the “Replace” field empty. Mergado will then remove all found occurrences of these texts from the element.
What does “Case sensitive” mean?#
If you check this option, Mergado distinguishes between lowercase and uppercase letters. For example, searching for SALE will not find sale. If unchecked, the search is case-insensitive.
What is the “Regular expressions” option for?#
When enabled, you can use regular expressions (regex) – patterns for advanced text searching and editing. For example, for swapping paragraphs, replacing numbers, removing multiple spaces, or reformatting data. Example: the expression ^(.*?)\n\n(.*)$ splits text into the first and second paragraphs.
What if I want to replace multiple different texts at once?#
You can add multiple rows to the rule – each with a different “Find” and “Replace” combination. Mergado processes them from top to bottom, so if some expressions overlap, their order determines the result. Tip: Place simpler expressions in the first rows and more complex ones (e.g., regular expressions) at the end.
How can I replace a certain word with another?#
In the “Find” field, type the original text (e.g., couch) and in the “Replace” field, type the new text (e.g., sofa). The rule will then replace all found words in the selected element.
Can I use a variable in the Find and Replace rule?#
Yes. You can enter variables in the “Find” or “Replace” fields – for example, %size% or %brand%. Mergado will then substitute the corresponding element value for each product.
What happens if the expression I am searching for does not exist in some products?#
Nothing happens – the rule is skipped without an error. The product remains unchanged. This is useful, for example, when you use the rule with the “All products” query, but the search term only appears in some of them.
How can I remove multiple spaces that appeared after editing text?#
Use the Find and Replace rule with a regular expression:
- Find:
\s{2,}(two or more spaces) - Replace: (one space)
This will consolidate excess spaces after removing texts or empty variables.
Can I use this rule to swap the order of paragraphs in text?#
Yes. Use the regular expression:
-
Find:
^(.*?)\n\n(.*)$ -
Replace:
\2\1
This swaps the first and second paragraphs. Tip: The rule works best when there is an empty line (double \n\n) between paragraphs.
What is the difference between using text and a regular expression?#
Text search works with exact matches (e.g., searches for an exact word or phrase). Regular expressions allow you to search for patterns – e.g., all numbers, email addresses, tags, or anything between two characters. For more complex edits, regex is more suitable.
What does it mean that the rule is applied from top to bottom?#
Mergado processes all rows of the rule in the order they are listed – from top to bottom. If the first row modifies the text, the second row already works with the modified version. This allows chaining multiple edits but requires careful planning of the order.
How can I replace, for example, the currency “CZK” with “EUR” or remove slashes from a string?#
In the “Find” field, type CZK (or /) and in the “Replace” field, type EUR (or leave it empty if you want to remove the character). You can also create multiple rows – one for currency, another for other edits (e.g., campaigns or text formatting).
Can the Find and Replace rule be combined with other rules, such as Rewrite or Remove diacritics?#
Yes. However, keep in mind that rules are applied from top to bottom and their order matters. Remember that the Find and Replace rule can completely or partially rewrite an element’s value, so it is important to carefully consider its placement among other rules.
How do I check if the edits were applied correctly?#
After saving and applying the rules, or regenerating the feed, check the result directly in the output feed or in the product preview on the Products page. For a detailed check of a specific product, you can use the “Rule walkthrough” feature, which shows how values change after each rule is applied.
Can I remove only part of the text within a single element?#
Yes. In the “Find” field, paste the specific word or phrase you want to remove, and leave the “Replace” field empty. Mergado will remove only this text, and the rest of the element will remain unchanged.
What should I do if I need to remove HTML tags (e.g., <p>, <br>, <strong>) in large quantities from descriptions?#
Use a regular expression that captures all HTML tags:
- Find:
<[^>]*>(example regex; individual cases may require adjustments) - Replace: (leave empty)
This will remove all HTML tags, leaving only plain text.
Can the rule be used on numbers, prices, or parameters?#
Yes. The rule can be used on any element that contains text – including numeric values, prices, or PARAM | PARAM_VALUE. For example, you can change the decimal separator, remove units, or add supplementary text.
What should I do if the regular expression behaves differently than expected?#
Check that the “Regular expressions” option is enabled. If it is, verify the syntax – for example, using an online tool like regex101.com. Tip: For more complex expressions, test on a smaller sample of products first before applying the rule broadly. You can also contact our support team.
Can the rule be used to replace multi-line text?#
Yes. Regular expressions can also work with paragraphs or line breaks (\n, \r\n).