Skip to content

contains - Check for the present of a substring

contains returns true if the given substring appears anywhere in string; otherwise it returns false. The check is case sensitive. To perform a case-insensitive match, normalize both values with toLowerCase() or toUpperCase() before calling contains.

Syntax

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

contains(string: string, substring: string): bool
string: string.contains(substring: string): bool

Arguments

NameTypeRequiredDescription
stringstringtrueThe full string, i.e the haystack
substringstringtrueThe substring for which we'll search in the full string, i.e the needle

Example - Check if an AWS Account ID appears in an ARN

Sometimes we only have a broader field, like an ARN, rather than its constituent parts. In this case, the contains function can be used to inspect values within the string.

create is_from_account from contains(arn_field, '074157727657')
create is_from_account from arn_field.contains('074157727657')

This will produce a field called is_from_account which is true if the ARN contains the associated AWS account ID.

Example - Check if a domain appears within a path

We can use contains to check if a domain appears within a given URL, for example:

create is_from_google from contains(url, 'google.com')
create is_from_google from url.contains('google.com')

This will produce a field called is_from_google that is true is the URL contains google.com.