I would like to check in KQL (Kusto Query Language) if a string starts with any prefix that is contained in a list.
Something like:
let MaxAge = ago(30d);
let prefix_list = pack_array(
    'Mr',
    'Ms',
    'Mister',
    'Miss'
);
| where Name startswith(prefix_list)
I know this example can be done with startswith("Mr","Ms","Mister","Miss") but this is not escalable.
an inefficient but functional option would be using matches regex - this can work well if the input data set is not too large:
let T = datatable(Name:string)
[
    "hello" ,'world', "Mra", "Ms 2", "Miz", 'Missed'
]
;
let prefix_list = pack_array(
    'Mr',
    'Ms',
    'Mister',
    'Miss'
);
let prefix_regex = strcat("^(", strcat_array(prefix_list, ")|("), ")");
T
| where Name matches regex prefix_regex
| Name | 
|---|
| Mra | 
| Ms 2 | 
| Missed | 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With