EEEEH
EEEEH

Reputation: 779

Kusto query for email filtering with regex

Raw string:

| Mail_To_s                                        |
| "[email protected],[email protected],[email protected],[email protected]"|

Current query:

CUSTOM_LOG_TABLE
| extend mail_count = countof(Mail_To_s, @"@", "regex")
| extend internal_mail_count = countof(tolower(Mail_To_s), @"yyy.com|zzz.com", "regex")
| extend external_mail_conut=mail_count - internal_mail_count
| where external_mail_count > 0

Results:

| mail_cout | internal_mail_count | external_mail_count | Mail_To_s                                        |
|     4     |          2          |           2         | "[email protected],[email protected],[email protected],[email protected]"|

Expect results:

How to extend column "external_email" for email filtering with regex

| mail_cout | internal_mail_count | external_mail_count | external_mail                 | Mail_To_s                                       |                         
|     4     |          2          |           2         | ["[email protected]","[email protected]"] |"[email protected],[email protected],[email protected],[email protected]"|

Upvotes: 0

Views: 563

Answers (1)

Avnera
Avnera

Reputation: 7608

Here is one approach:

datatable(Mail_To_s:string)["[email protected],[email protected],[email protected],[email protected]"]
| extend mail_count = countof(Mail_To_s, @"@", "regex")
| extend internal_mail_count = countof(tolower(Mail_To_s), @"yyy.com|zzz.com", "regex")
| extend external_mail_count=mail_count - internal_mail_count
| where external_mail_count > 0
| extend external_mail   = split(Mail_To_s,",")
| mv-apply external_mail   on (
     parse external_mail   with * "@" Domain
     | where Domain !in("yyy.com", "zzz.com")
     | summarize external_mail= make_set(external_mail)
)
| project-reorder mail_count, internal_mail_count, external_mail_count,external_mail
mail_count internal_mail_count external_mail_count external_mail Mail_To_s
4 2 2 [
"[email protected]",
"[email protected]"
]
[email protected],[email protected],[email protected],[email protected]

Upvotes: 2

Related Questions