containsAny
containsAny, function
def pure containsAny(haystack: text, needles: text, separator: text): boolean
Indicates whether a haystack
contains any needle, as obtained by splitting the needles
through the separator
.
haystack
: the full textneedles
: the needles to be searched in the haystackseparator
: the text field separator to be found in theneedles
Example
haystack = "1+2+3+4"
needles = "-,+,*,/"
separator = ","
show scalar "" with
containsAny(haystack, needles, separator) // 'true'
Remarks
The separator
cannot be an empty text value.
This function is case-sensitive, and also sensitive to parasite spaces around your separator
.
Recipes and best practices
This function is generally used to detect entries that you want to exclude. In this case, you just have to list all strings that are forbidden in your entry, and then filter out the entries.
ToRemove = "TODELETE,deprecated"
keep where not containsAny(Items.Name, ToRemove, ",")
Also, be careful because this function is case-sensitive. If you have different cases in your data for the same information, it is highly recommended to homogenize the cases in the processing pipeline.
Items.Decription = "Blue Pants"
Items.IsBlueCaseSensitive = containsAny(Items.Description, "blue,red,green", ",") // 'false'
Items.IsBlue = containsAny(~Items.Description, ~ "blue,red,green", ",") // 'true'
Items.IsBlueUppercased = containsAny(uppercase(Items.Description), "BLUE,RED,GREEN", ",") // 'true'