Splunk Search

Search for multiple apperances of a pattern in a field

KMoryson
Explorer

Hi, is there a way to search for more than one appearance of a pattern in a string?

For example:
Command
cmd.exe c:\windows\\\\\\\\sytem32\[...]
cmd.exe c:\windows\sytem32\[...]

I would want to search for rows with more than single consecutive "\" , in case of above only first row to be returned.

Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Have you even tried it?

Due to the way splunk escapes backslash in regex expressions, you need 4 backslashes to match a single backslash in the field, therefore 8 backslashes (as I have used), will find anything more than 1 in the field.

| makeresults
| eval _raw="cmd.exe c:\\windows\\\\\\\\\\\\\\\\sytem32\\[...]
cmd.exe c:\\\\windows\\\\sytem32\\\\[...]
cmd.exe c:\\windows\\sytem32\\[...]"
| multikv noheader=t
| regex _raw="\\\\\\\\"

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| regex _raw="\\\\\\\\"

KMoryson
Explorer

This only matches to this specific amount of backslashes, I want to match for any number above one

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Have you even tried it?

Due to the way splunk escapes backslash in regex expressions, you need 4 backslashes to match a single backslash in the field, therefore 8 backslashes (as I have used), will find anything more than 1 in the field.

| makeresults
| eval _raw="cmd.exe c:\\windows\\\\\\\\\\\\\\\\sytem32\\[...]
cmd.exe c:\\\\windows\\\\sytem32\\\\[...]
cmd.exe c:\\windows\\sytem32\\[...]"
| multikv noheader=t
| regex _raw="\\\\\\\\"

KMoryson
Explorer

So sorry, you are right, this works wonderfully, thank you for help

0 Karma
Get Updates on the Splunk Community!

New Case Study Shows the Value of Partnering with Splunk Academic Alliance

The University of Nevada, Las Vegas (UNLV) is another premier research institution helping to shape the next ...

How to Monitor Google Kubernetes Engine (GKE)

We’ve looked at how to integrate Kubernetes environments with Splunk Observability Cloud, but what about ...

Index This | How can you make 45 using only 4?

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