Skip to content

matches

Description

Returns true if a string matches a given regular expression. The expression is applied to the entire string; partial matches return false.

Syntax

Like many functions in DataPrime, matches supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

matches(value: string, pattern: regexp): bool
(value: string).matches(pattern: regexp): bool

Arguments

NameTypeRequiredDescription
valuestringtrueThe string to test
patternregexptrueThe regular expression to test against

Example

Detect malformed fields

Consider the following documents:

{ "msg_structured": "User Chris bought 10 Sunglasses" }
{ "msg_structured": "User James bought 1 Bed" }
{ "msg_structured": "User Rick won't give you up" }

The third entry is incomplete. Use matches to filter out malformed values:

filter !matches(msg_structured, /User [a-z|A-Z]+ bought \d+ [a-z|A-Z]+/)
filter !msg_structured.matches(/User [a-z|A-Z]+ bought \d+ [a-z|A-Z]+/)

Output

{ "msg_structured": "User Rick won't give you up" }