Splunk Search

How to edit the syntax for my rex search to extract the folder name from a source path?

Federica_92
Communicator

Hi everyone,

I'm struggling with this rex expression:

 query | rex field=source  "/var/syslog*(?<remote_source>\w+)/*.log"

  /var/syslog/name_folder/2015-08-11.log

I need to get the folder name. Could someone please help me to correct this regex?

Thank you a lot! : )

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

query | rex field=source  "^\/(?:[^\/]+\/){2}(?<remote_source>[^\/]+)\/"

View solution in original post

woodcock
Esteemed Legend

Like this:

query | rex field=source  "^\/(?:[^\/]+\/){2}(?<remote_source>[^\/]+)\/"

richgalloway
SplunkTrust
SplunkTrust

Don't forget the escape characters.

^\/(?:[^\/]+\/){2}([^\/]+)\/
---
If this reply helps you, Karma would be appreciated.

woodcock
Esteemed Legend

quite correct; Fixed another markdown mistake, too (answer updated and tested).

0 Karma

Federica_92
Communicator

Thank you : )

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...