Splunk Search

REX Comand -> does it accept wildcards?

lpolo
Motivator

I have some information I need to extract from the source field but I cannot do it for all cases:
Example:
I have these two sources
\/usr\/local\/dir-hello\/logs\/
\/usr\/local\/dir\/logs\/

So the REX for each will be:
rex field=source "\/usr\/local\/dir-hello\/logs\/(?.*?)\/"

rex field=source "\/usr\/local\/dir\/logs\/(?.*?)\/"

These REX works but I need:

rex field=source "\/usr\/local\/dir*\/logs\/(?.*?)\/"

It does not work. How can I fix it?

Thanks,
Lp

Tags (1)
0 Karma

bwooden
Splunk Employee
Splunk Employee

rex uses regular expressions. You should be able to use greedy matches to extract a field named job from the fifth path segment in both of your sources with one expression. One example:

rex field=source "/usr/local/dir(?:[^/]+)?/logs/(?<job>[^/]+)/"

Or are you wanting job to be everything to the left of a period at end of the path? An example of that:

rex field=source "/usr/local/dir(?:[^/]+)?/logs/(?<job>[^\.]+)"

lpolo
Motivator

Thank you It worked.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...