Splunk Search

How to use rex to get matching number?

xinde
Path Finder

I tried to use | rex "^Version\s(?P(\\d{2}))$ to extract version number - it should only be 2 digit number.
But 12.1.0.2.0 returned as well and I am not sure if this is a Splunk issue or my SPL issue.

Any help is appreciated here.

0 Karma
1 Solution

xinde
Path Finder

Thanks guys for your quick help....

I find a way to work around. instead of just get the numbers, I put string content in the rex... it works.

View solution in original post

0 Karma

xinde
Path Finder

Thanks guys for your quick help....

I find a way to work around. instead of just get the numbers, I put string content in the rex... it works.

0 Karma

xinde
Path Finder

sourcetype=testData
| rex "^Version\s(?P(\d{2}))$"
| chart values(version)

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Can you share some sample data?
Have you tried \d instead of \\d?

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

xinde
Path Finder

Thanks for reply, I Just tried \d, same return...
This is the line I would like to capture: "Version 18"

There are lines related to 12.1.0.2.0
Version 12.1.0.2.0 - Production

Not sure why both 18 and 12.1.0.2.0 are returned with that query...
$ seems does not work here either.

0 Karma

somesoni2
Revered Legend

What's your full search??

0 Karma

xinde
Path Finder

sourcetype=test
| rex "^Version\s(?P(\d{2}))$" | chart values(version)

pretty simple query here....

0 Karma

niketn
Legend

Can you add sample raw data for both kind of events?
Is Version to be extracted always within double quotes? As it is in your example "Version 18".

Since regular expressions are patter based if you provide a sample of the two events we can use before and after content to form the right regular expression.

Following is the extraction based on your sample data (however as stated this might not work unless you provide us with some sample events as is. You can mock/anonymize and sensitive information as required)

| makeresults
| eval data="Version 18;Version 12.0.0.2"
| makemv data delim=";" 
| mvexpand data
| rename data as _raw
| rex "Version\s(?<version>\d{2})(?!\.)"
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

xinde
Path Finder

Raw Data as follow:

<2018-03-15 11:06:43.958>
Version 18
<2018-03-15 11:06:44.040> Detected Release 12.1.0.2.0
<2018-03-15 11:06:44.049> Detected Release 12.1.0.2.0
Linux: Version 12.1.0.2.0 - Production on 15-MAR-2018 11:06:14

No double quotes 🙂

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...