String Operators

String operators provide functionality for string manipulation and comparison in DataLogic-rs rules.

cat
substr
replace
split
starts_with
ends_with
upper
lower
trim

cat

The cat operator concatenates multiple strings together.

Syntax

{ "cat": [string1, string2, ...] }

Parameters

Parameter Description
strings An array of strings or expressions that evaluate to strings

Example: Simple String Concatenation

Rule:

Data:

Result:

Example: Concatenation with Variables

Rule:

Data:

Result:

substr

The substr operator extracts a substring from a string, starting at a specified position and optionally extracting a specified number of characters.

Syntax

{ "substr": [string, start_index, length] }

Parameters

Parameter Description
string The input string to extract from
start_index The start position (0-indexed)
length (optional) The number of characters to extract (if omitted, extracts until end of string)

Example: Extract Substring

Rule:

Data:

Result:

Example: Extract to End of String

Rule:

Data:

Result:

replace

The replace operator replaces all occurrences of a specified string with another string.

Syntax

{ "replace": [string, find, replacement] }

Parameters

Parameter Description
string The input string to perform replacement on
find The string to find and replace
replacement The string to replace matches with

Example: Simple Text Replacement

Rule:

Data:

Result:

Example: Remove Text (Replace with Empty String)

Rule:

Data:

Result:

split

The split operator splits a string into an array of substrings based on a delimiter. When the delimiter contains regex named groups (using (?P<name>...) syntax), it extracts those groups as an object instead of performing a normal split.

Syntax

{ "split": [string, delimiter] }

Parameters

Parameter Description
string The string to split or extract from
delimiter The string to use as a separator, or a regex pattern with named groups for extraction

Return Value

Condition Return Type Description
Normal delimiter Array of strings Split string into array parts
Regex with named groups Object Extracted named groups as key-value pairs
Regex no match Empty object Returns {} when pattern doesn't match

Example: Split CSV Data

Rule:

Data:

Result:

Example: Split into Words

Rule:

Data:

Result:

Example: Complex Processing with Split

Rule:

Data:

Result:

Example: Regex Extraction - IBAN Pattern

Rule:

Data:

Result:

Example: Regex Extraction - Email Pattern

Rule:

Data:

Result:

Example: Fallback to Normal Split

Rule:

Data:

Result:

Notes

  • For regex extraction, the delimiter must contain named groups using (?P<name>...) syntax
  • Returns an object with extracted groups when regex named groups are found and match
  • Returns empty object {} when regex doesn't match the input string
  • Falls back to normal string splitting when regex compilation fails or no named groups are present

starts_with

The starts_with operator checks if a string starts with a specified prefix.

Syntax

{ "starts_with": [string, prefix] }

Parameters

Parameter Description
string The string to check
prefix The prefix to look for at the start of the string

Example: Check if string starts with prefix

Rule:

Data:

Result:

Example: Case sensitivity

Rule:

Data:

Result:

ends_with

The ends_with operator checks if a string ends with a specified suffix.

Syntax

{ "ends_with": [string, suffix] }

Parameters

Parameter Description
string The string to check
suffix The suffix to look for at the end of the string

Example: Check if string ends with suffix

Rule:

Data:

Result:

Example: Using with conditional

Rule:

Data:

Result:

upper

The upper operator converts a string to uppercase.

Syntax

{ "upper": string }

Parameters

Parameter Description
string The string to convert to uppercase

Example: Convert string to uppercase

Rule:

Data:

Result:

Example: Combining with other operators

Rule:

Data:

Result:

lower

The lower operator converts a string to lowercase.

Syntax

{ "lower": string }

Parameters

Parameter Description
string The string to convert to lowercase

Example: Convert string to lowercase

Rule:

Data:

Result:

Example: Case-insensitive comparison

Rule:

Data:

Result:

trim

The trim operator removes whitespace characters from the beginning and end of a string.

Syntax

{ "trim": string }

Parameters

Parameter Description
string The string to trim

Example: Remove leading and trailing whitespace

Rule:

Data:

Result:

Example: Combine with other operators

Rule:

Data:

Result: