Splunk Search

Extract a part of field

Olivier2024
Explorer

Hi all,

I'm trying to extract a part of a field. The field named Computer and is like MySrv.MyDomain.MySubDom1.com

MySubDom1 can exist or not.

I would like to extract everything after MySrv. I tried with  index=MyIndex host=MySrv | rex field=_raw "(?<domaine_test>(\.\w+))"

The result create a new field Domain_test but it stores only the first part "MyDomain" and not the rest of the field.

How can I do this ?

For exemple :

Computer = "MySrv.MyDomain.MySubDom1.com"
Result : Domain_test = "MyDomain.MySubDom1.com"

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex "\w+\.(?<domaine_test>[\.\w-]+)"

if the - is at the end of the character class [] it doesn't need to be escaped

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| rex "\w+\.(?<domaine_test>[\.\w]+)"
0 Karma

Olivier2024
Explorer

Hi,

Thank you for your response.

I have some domain with "-" character, for exemple black-ice.com
The result is "black". Is it possible to get all domain ?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "\w+\.(?<domaine_test>[\.\w-]+)"

if the - is at the end of the character class [] it doesn't need to be escaped

Olivier2024
Explorer

It works 🙂

Many thanks for your help !

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...