Splunk Search

How do you extract a field using regex?

shivam2411
New Member

00000887 ThreadMonitor W WSVR0606W: Thread "WebContainer : 24" (00000887) was previously reported to be hung but has completed. It was active for approximately 1386249 milliseconds. There is/are 0 thread(s) in total in the server that still may be hung.

Here, I want to extract 1386249 and thread count using a regex expression.

Tags (2)
0 Karma

woodcock
Esteemed Legend

Try (?<milliseconds>\d+)\s+milliseconds\D+(?<thread_count>\d+).

0 Karma

saurabhkharkar
Path Finder

The above regex should work , but this should take care of the singular / plural aspect of the number of threads - Please remove spaces before msec and threads in the regular expression below.

"approximately\s+(?< msec>\d+).*?[is|are]\s+(?< threads>\d+)"

0 Karma

richgalloway
SplunkTrust
SplunkTrust

If you enter the regex string as code by indenting four spaces or surrounding it with backticks there's no need to mangle it.

This expression won't work if it contains literally "is/are" as in the example.

---
If this reply helps you, Karma would be appreciated.
0 Karma

saurabhkharkar
Path Finder

Thanks for the tip about entering the string as a code.
If the string is going to be 'is/are' always you are right (this wont work).
I was guessing it would be either 'is' or 'are' based on the number of threads.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this regex string.

"approximately (?<msec>\d+).*?are (?<threads>\d+)"
---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Converted this response to an unrelated question into a new question.

---
If this reply helps you, Karma would be appreciated.
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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...