Policies & Guidelines

EXCLUDE_BY_REGEX

Remove objects from an array by a key-regex match

Description

Removes objects from an array by matching the value of a given key to a regular expression pattern.

Iterates through the array, checking if the value of each object's Key property matches the regex Pattern. Returns a new array which doesn't contain matched objects.

For example, given Key "name" and Value /John/, all objects in the source Array whose name property contains the string "John" would be removed from the returned array.

Function signature

EXCLUDE_BY_REGEX(array: Array, key: String, pattern: String) => Array

Parameter

Description

Array

Array to exclude objects from

Key

Key whose value to match

Pattern

Regex pattern to match

Examples

array = [{"a":2},{"a":"foo bar"},{"a":"foo","b":3}]
key = "a"
stringPattern = "^foo"

Formula

Return value

EXCLUDE_BY_REGEX(array, key, stringPattern)

[{"a":2}]