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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...