Splunk Search

What regex to use to drop everything after the last occurrence of a symbol?

jpfrancetic
Path Finder

Hi Splunk Community,

I am working on a regex to filter the sources I am getting from logs. I am trying to drop everything after the last "/" in the field but I am having problems filtering.

My current sources look something like: /db2audit/fs01/db2inst1/extract/abc123/file.del

I am trying to filter it to look like: /db2audit/fs01/db2inst1/extract/abc123

Thanks in advance!

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try this command.

| rex mode=sed field=foo "s/(.*)\/.*?$/\1/"
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @jpfrancetic,

if the first part is fixed in the first four folders, you could extract something like this:

| rex field=source "^(?<path>(\/\w+){4}).*(?<filename>\/\w+\.\w+$)"

that you can test at https://regex101.com/r/j7XgJ5/1

Ciao.

Giuseppe

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this command.

| rex mode=sed field=foo "s/(.*)\/.*?$/\1/"
---
If this reply helps you, Karma would be appreciated.
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @jpfrancetic,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

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 ...