Using Regular Expressions

Prev Next

Using attribute mapping rules, you can map attributes between source and target catalogs. Similarly, using regular expressions, you can further transform values into the desired format as needed for the target catalog. Many attribute mapping rules enable the use of regular expressions to derive at the required value.

Following shows the Regular Expression Builder screen displayed when you select the Regex option from the Create Attribute Mapping page.

A screenshot of a computer  Description automatically generated with medium confidence

Following is an overview of the various fields displayed in the screen:

  • Enter a description for this expression: A brief description of the regular expression that you are going to build for better reference.

  • Search Expression: This section lists all the expressions that were created.

A picture containing text, screenshot, line, font  Description automatically generated

  • Replacement Expression: This is an open field that determines what will replace the existing source value, or what the resulting target value will be after RegEx is applied. This is typically taken from the column headers in the Sample Values field. The default is the initial value, “$0”.

A picture containing text, screenshot, font, line  Description automatically generated

  • Sample Values: This shows the values of the attribute selected in the Value column. Based on the expression generated, the sample values are displayed in the next columns “$0”, “$1” and so on. You can enter a Replacement Expression as $0 / $1 depending on the value to be used using column headers in the Sample Values.

A screenshot of a computer  Description automatically generated with low confidence

  • Toolbox: This contains various building blocks that can be added as a foundation to the Search Expression. These are required to create the expression needed to derive at the required value.

A screenshot of a phone  Description automatically generated with low confidence

  • Saved Templates: It lists all the previously created and saved regular expressions. You can save any expressions created for future use, rather than recreating the same expressions repeatedly across a project. Click Saved New Template and the expression created will be added in this list.

A screenshot of a computer  Description automatically generated with medium confidence

Depending on the value to be extracted from the existing value, there are multiple ways in which expressions can be created.

Let us consider an example of a product Tool Kits wherein a source attribute Type has value as:

  • VisionTek PC Toolkit 26 Piece

  • VisionTek Mac Toolkit 12 Piece

  • StarTech.com 19 Piece Computer Tool Kit in a Carrying Case - 19 Piece(s) - Vinyl - TAA Compliant

Suppose there is a target attribute Number of pieces which should have Value as the number (26, 12, 19) and UoM as pieces.  To derive the value and UoM from the existing source attribute, you need to use regular expressions. Let us understand how to create a regular expression and use it as value and UoM.

Let us use the rule Split source attribute value to explicit target attribute value and UoM as explained in section Split source attribute value to explicit target attribute value and UoM to create the regular expression.

To create a regular expression:

  1. Click the first link Add regular expression for 1st part of Value Split.

    Since the source attribute Type is selected, its values are displayed in the Sample Values section in the first column. Now, we need to derive the numbers (26, 12, 19) from these values which will be used as a value for the target attribute.

  2. In the Search Expression, select the value as Contains from the drop-down list as shown below.

    A screenshot of a computer  Description automatically generated with low confidence  

  3. Drag the Toolbox, Character Type in the Search Expression and select the relevant instance of the character from the drop-down which results in the required value.

  4. This means that from the existing value, display one or more instance of character that contains decimal value. Thus, the value needed for the target attribute is now displayed in column $1.

    If you want to delete an expression, you can simply drag and drop the expression into the Trash.

  5. Enter the Replacement expression as $1 as the required value is in this column.

  6. Enter a description for this expression to save it and then click Save New Template so, that it can be reused for similar instance. If you don’t intend to save the expression, you can directly click on Submit to apply the expression.

  7. Similarly, click the second link Add regular expression for 2nd part of Value Split.

    The first value created still exists and to create the second value, you need to clear the old expression.

  8. Click Reset Form and the existing search expression is deleted. Now, we need to derive the value piece to be used as UoM for the second target attribute.

  9. In the Search Expression, select the value as Contains from the drop-down list as shown below.

  10. Drag the Toolbox, Custom Expression in the Search Expression and type the word Piece which will result in the required value.

    This means that from the existing value, display the word piece. Thus, the UoM needed for the target attribute is now displayed in column $1.

  11. Enter the Replacement expression as $1 as the required value is in this column.

    Thus, the value can now be used as a UoM for the second target attribute.

    Similarly, you can use various options available under Toolbox to parse the data in the string and capture the value in the string.

Regular Expressions can handle almost any value transformation. In addition to removing special characters, the RegEx Builder is useful in parsing complex values such as a single attribute “Overall Dimensions” (consisting of: Length x Width x Thickness) to be mapped to separate target attributes such as “Length”, “Width”, and “Thickness”. Since expressions can be saved across a project, you only need to create the regular expression once, and can use the same expression across the rest of the project. String operations can also help to achieve the same output.