Splunk Search

How do I write the regular expression to extract the domain name from email addresses in SMTP logs?

jspvkey
Explorer

Hi,

I am really new to Splunk and Regular Expression stuff. I was planning to extract just the domain names of all e-mail senders in my SMTP Log. For example, If the sender field value is store_news @amazon.com, then I just want to extract the domain name which is amazon.com. Can somebody please provide me a way to perform this?

Thanks
Appreciated

0 Karma

mhassan
Path Finder

Here is another one

@(?\w+.\w{3})
0 Karma

lguinn2
Legend

This one won't work for all email addresses...

0 Karma

martynoconnor
Communicator

Agreed, there are top level domains with shorter and longer lengths. Also the dot isn't escaped.

0 Karma

jluo_splunk
Splunk Employee
Splunk Employee

If you are uncomfortable with regular expressions, you can use the Interactive Field Extractor. Documentation here: http://docs.splunk.com/Documentation/Splunk/6.3.2/Knowledge/ExtractfieldsinteractivelywithIFX

0 Karma

somesoni2
Revered Legend

Try something like this

your base search  | eval sender_domain=mvindex(split(sender,"@"),-1) .....

OR

your base search  | rex field=sender ".*@(?<sender_domain>.*)" 

thahn
Explorer

Based on your answer, I used the following to extract the domain part and sort by number of occurrences for the top 20:

your base search | eval sender_domain=mvindex(split(sender,"@"),-1)  | top limit=20 sender_domain
0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...