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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...