Splunk Search

regex help

saurabhkunte
Path Finder

I have following as raw events

Message=Total db time 272 seconds
Message=Total db time 2,272 seconds
Message=Total db time 32,272 seconds

I am able to extract the digit via regex, but unable to modify the regex to include numbers separated with comma. Any help appreciated.

Here is my current regex
rex "db time (?\d*)" -- This extracts the value 272, but not the other numbers with commas.

Tags (1)
0 Karma
1 Solution

javiergn
Super Champion

Try this instead:

rex "db time (?<time>[\d\,]+)"

If you want something more robust that supports decimals with both comma and dot try this instead (not tested but logic is fine):

| rex "db time (?<time1>\d+)[\,\.]?(?<time2>\d+)?"
| eval time = time1 . time2

View solution in original post

javiergn
Super Champion

Try this instead:

rex "db time (?<time>[\d\,]+)"

If you want something more robust that supports decimals with both comma and dot try this instead (not tested but logic is fine):

| rex "db time (?<time1>\d+)[\,\.]?(?<time2>\d+)?"
| eval time = time1 . time2

saurabhkunte
Path Finder

Many thanks, this works very well.

0 Karma
Get Updates on the Splunk Community!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...