Replace text

Value resolver – Abstract

Purpose: Searches the string in the input value for matches to the Search text and applies the replacement defined by Replace with to produce the return value.

images/download/attachments/78258512/image2022-6-28_13-0-48-version-1-modificationdate-1656414048804-api-v2.png

The Replace text value resolver searches within the string in the input value for matches to the Search text, and applies the replacement defined by Replace with to produce the return value.

  • If no value ($null) is present as input value, no value ($null) is returned.

  • For input values that are not strings, their string mapping is processed.

The Regular expression? option can be used to interpret the Search text as a regular expression. In this case the expression for Replace with also supports references to groups defined in the Search text ($1, $2, ...).

Configuration

Parameter

Meaning

Search text

This parameter defines the substring searched for in the input value or the regular expression that identifies passages to be replaced.

Replace with

This parameter defines the string that will be inserted in the input value at each passage that is considered a match for the Search text.

In conjunction with the Regular expression? option, the replacement expression can use placeholders for groups defined in the Search text ($1, $2, ...).

Regular expression?


The Regular expression? option decides whether the Search text is interpreted as a regular expression or (by default) searched for as plain text in the input value.

NOTE◄ The Search text and Replace with parameters can be specified by direct input (as text) or via value resolvers at runtime.

In the example on the right, the Search text was entered directly as static text (#company#). Since the Regular expression? option is not checked, the input value is searched for all matches to this string.

The value for Replace with is determined via the Company of session value resolver at runtime. Each match for the Search text (#company#) is replaced with the name (address.name1) of the company from the applicable login context.

NOTE◄ Starting from the direct input provided by default, the definition of a value resolver must be initiated by clicking on the small gray arrow in the lower left corner of the input value (see Search text in screenshot). If 'no value' (from the context menu) is selected instead of a value resolver, the direct input appears again the next time the Replace text value resolver is expanded.

images/download/attachments/78258512/image2022-6-28_13-1-54-version-1-modificationdate-1656414114224-api-v2.png

Examples

Simple example ('Regular expression?' option unchecked)

The input value is a string containing different characteristics of a container (BIC code, color, size, etc.) separated by spaces. Example: SCMU3216083 WHT/BLU 40ft

In a notification, this string is formatted to insert a line break and semigraphic characters (└─) instead of the space character, so that the information after the BIC code appears like detail elements in a tree.

Runtime example: (with the sample data given above)

images/download/attachments/78258512/image2022-6-27_17-18-28-version-1-modificationdate-1656343108923-api-v2.png

Configuration:

Within the Show alert (Popup) event action, the Replace text value resolver is parameterized as follows to process the input value present here as a reference object into the desired output text for the Message:

  • A blank " " character was entered here directly as static text as the Search text. The blank character is not visible in the image.

    NOTE◄ By text marking (e.g. Ctrl+A) in the input field the blank space can be made indirectly visible.

  • A line break is entered in the Replace with string (directly using the Enter key and not, for example, as HTML newline \n). Two characters follow, which can be entered e.g. with pressed Alt key via numeric keypad (Alt+192, Alt+196).

images/download/attachments/78258512/image2022-6-28_13-4-32-version-1-modificationdate-1656414272345-api-v2.png

More complex example ('Regular expression?' option checked)

The previous example is now adapted under the assumption that the string with the 'Container details' in the input value always contains the same tokens (@BIC@ @COLOR@ @SIZE@) in exactly this order.

On this basis, this information is converted into an XML structure:

Target structure (schematic)

Runtime example


<container bic=@BIC@>
<color>@COLOR@</color>
<size>@SIZE@</size>
</container>

images/download/attachments/78258512/image2022-6-27_17-49-27-version-1-modificationdate-1656344967812-api-v2.png

Configuration:

The Regular expression? option is set in the Replace text value resolver this time, because the input value can be conveniently 'separated' into the expected tokens with the help of a regular expression as Search text:

  • The first group ($1) includes all non-blank characters from the beginning of the string "(^\S+?)" to the first blank character "\s".

  • The second group ($2) includes all subsequent non-blank characters up to the next blank character.

  • The third group ($3) includes all the following non-empty characters.

The expression for Replace with transforms the acquired groups into XML format of the target structure by combining the placeholders with literals.

images/download/attachments/78258512/image2022-6-28_13-5-42-version-1-modificationdate-1656414342903-api-v2.png

Further examples ('Regular expression?' option checked)

The following table shows more examples of using regular expressions to Replace text:

Objective

Input value

Search text

Replace with

Result

Find and 'neutralize' container number at any position

CONTAINERS: SCMU3216083 WHT/BLU 40ft ABCU1234560 RED/YLW 20ft

\b[A-Z]{4}[0-9]{7}\b

@BIC@

CONTAINERS: @BIC@ WHT/BLU 40ft @BIC@ RED/YLW 20ft

Detect container number at any position and 'neutralize' all other text sections

CONTAINERS: SCMU3216083 WHT/BLU 40ft ABCU1234560 RED/YLW 20ft

(?<=^|\b[A-Z]{4}[0-9]{7}\b).*?(?=\b[A-Z]{4}[0-9]{7}\b|$)

" "

Blank character

SCMU3216083 ABCU1234560

Structured return of container number

SCMU3216083

(^[A-Z]{3})([A-Z])(\d{6})(\d)

$1 $2 $3[$4]

SCM U 321608[3]

Replace unit 'ft' or 'FT' for container size with minute symbol (')

(two alternatives)

CONTAINERS: SCMU3216083 WHT/BLU 40ft MFTU1234560 RED/YLW 20FT

/\b(\d+)ft\b/i

$1' Placeholder ($1) copies the group of numbers

CONTAINERS: SCMU3216083 WHT/BLU 40' ABCU1234560 RED/YLW 20'

CONTAINERS: SCMU3216083 WHT/BLU 40ft MFTU1234560 RED/YLW 20FT

/(?<=\b\d+)ft\b/i

'Positive lookbehind' checks if the group of numbers is prefixed

'

CONTAINERS: SCMU3216083 WHT/BLU 40' ABCU1234560 RED/YLW 20'