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
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 ...