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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...