Splunk Search

regex path without filename from source

Moritz
Explorer

Hallo,
I fruitless tried to extract the path from the source field. My latest test is:

source="C:\\Users\\...\\...\\Logs\\*"   | rex field=source "(?<path>.*)\\.*$"
Tags (3)
0 Karma
1 Solution

somesoni2
Revered Legend

Try this

| rex field=source "(?<path>.*)[//\\\]+.[a-zA-Z.]*"

View solution in original post

somesoni2
Revered Legend

Try this

| rex field=source "(?<path>.*)[//\\\]+.[a-zA-Z.]*"

Moritz
Explorer

@rahulroy_splunk: this is what i was searching for. thank you! thank you somesoni2 for your help.

0 Karma

rahulroy_splunk
Path Finder

This will also work.
| rex field=source "(?.*)[//\\\]"

somesoni2
Revered Legend

I am still not clear with the requirement. Would it be possible for your provide example. like for "C:\test\test9\some9sample.log", result should be "C:\test\test9"

0 Karma

Moritz
Explorer

my backslashes were deleted..

i'd like to accept in the filename all characters except the backslash. so i thougt for something like [\\][^\\]* for the last part. (i dont really understand [//\\\].)

0 Karma

somesoni2
Revered Legend

Could you be little more specific? probably an example?

0 Karma

Moritz
Explorer

Thank you.
A little bit better version is:
rex field=source "(?.)[//\\\]+.[a-zA-Z.0-9]"

How is it possible to find all characters except \ in the latter part?

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...