Splunk Search

Constructing a search term with ( AND ) statement (WITHIN) nth Characters

J_Walker_Ex
New Member

Hello ,

I am constructing search

At the moment I am looking for ( X AND Y AND Z)

This is working well but I am returning lots of results . see the made up examples below
XsoccerYfootballZ
XmancesterunitedYmanchestercityZ
timeZsleepingYthetimestherertertertertertredgfdX

what I would like to be able to do is restrict my results based on how many characters they are between one another

Ideally I would like X AND Y AND Z to be no more than three characters between. The dots represent the characters.
X...Z...Y

Also if possible I like it to be upto three characters

So it could be

X.Z...Y or X..Z...Y or X...Z..T and so on

So if its possible can I restrict the order that results have to be returned

So X has to become Z and Z has to be come before Y .

Is it possible to construct this sorts of searches terms ?

0 Karma

woodcock
Esteemed Legend

You cannot do this (or I should say, should not do this) with a base search so keep your base search but then you can user regex like this:

... | regex _raw="(?:X.{0,3}Z{0,3}Y)|(?:X.{0,3}Z{0,5}T)"
0 Karma

J_Walker_Ex
New Member

Hello thanks for getting back to my question . Where about would I introduce the regex into the search. I m relatively new to doing to splunk. Would this be a secondary process

0 Karma

woodcock
Esteemed Legend

It should be the first pipe in the list (just after your base search). You need to throw away the garbage as soon as possible in Splunk.

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

Perhaps something like:

... | rex "(?P<match>X{0,3}Z{0,3}Y)"
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...