Splunk Search

How can I extract this pattern from my raw data using rex command? \"ProductAccountNumber\":\"5342534253425342\"

tanvi1g
New Member

Hi,

Can someone able to help me please.

I'm very new to using Splunk and most certainly to the rex command and regular expressions, so please bear with.

I'm trying to extract an ProductAccountNumber field from my raw data which is in the following format
{ \"ProductAccountNumber\":\"5342534253425342\" }

Could someone possibly tell me please how I may strip the actual ProductAccountNumber out of this line.

Many thanks and kind regards

Tanvi

Tags (2)
0 Karma

niketn
Legend

@tanvi1g, while the following Regular Expression worked on https://regex101.com

\\\"ProductAccountNumber\\\"\:\\\"(?<ProductAccountNumber>\d+)\\\"

I had to introduce some extra escape characters in Splunk. Following is a run anywhere search based on your data:

| makeresults
| eval _raw ="{ \\\"ProductAccountNumber\\\":\\\"5342534253425342\\\" }"
| rex "\\\"ProductAccountNumber\\\\\"\:\\\\\"(?<ProductAccountNumber>\d+)\\\\\""

Please try out this rex and confirm.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

inventsekar
Ultra Champion

Please check this -
| makeresults
| eval _raw="{ \"ProductAccountNumber\":\"5342534253425342\" }"
| rex field=_raw "ProductAccountNumber\\\"\:\\\"(?P<ProdAccNo>\d+)" | table _raw ProdAccNo

alt text

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...