< Back
Print

Replace via regex pattern format plugin

Introduction

This format can replace or edit values using a regex pattern. Each matched result can be individually formatted.
It is also possible to define which matches will be returned after transforming them.
 

Configuration

First step is to select the format plugin in your datamap and click on the cogwheel to open up the configuration

Screenshot of selecting the Replace via regex pattern format plugin in the datamap

Each input field of the configuration will be explained in the following table

Screenshot of the empty configuration of the replace via regex pattern format plugin
FieldExplanationExample
Format of the source valueYou can initially format the input value through a format plugin before the regex operation is performedCS::Unformatted value (default)
Enter a patternThe regex pattern that you want to use on your input value.
Important: Every regex pattern needs to start and end with “/” (slash)
/\{(\d+)\}/
Define which callback is to replace and howFor each match of your pattern (callbacks) you can create a transformation. With the plus-icon you can add multiple rows. The amount of selectable callback variables is defined by your regex patternConfigured in the example export below
Define which callback variables are to be returned and howStructure of the formats result value. You can access the transformed callbacks the same way you would access placeholders using brackets: {}Returning the first and second callback variable with an underscore in between:
{$1}_{$2}
Optionally, specify a sample string to run your pattern with so you can see the result hereCompletly optional, you can inset a string / value and after saving the format, you can see in the next field “Result of the preg_match with your sample value” the result of the regex execution on your string

 

Example

For this example we will export attribtues from a product. The attribute name should be converted from e.g. “Global Color Code” to only export “Color”.
Therefore we will build a loop where we export the key and value, but the key will be transformed using regex

 

Attributes on Product

Screenshot of attributes on product for regex example

Excerpt from the configuration
There is a loop head configured with the two attribtues selected as context. From these attributes the Label gets exported as array key. The transformation for the attribute label can be seen below.
The selected pattern where a callback variable {$1} extracts the value between “Global” and “Code”. To showcase how the regex works on such value, there is an example string configured where the pattern is used with.

Screenshot of the regex pattern´for the example configuration

 

Example Exported Data

Screenshot example export attribute data with regex
Was this article helpful?
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Tags:
Table of Contents