Splunk Dev

REX

edfigue88
Explorer

Hello,  I'm not so good with REX formula, if someone can help me and give me some tip for next time, I appreciate, thanks.

I need to extract the balance (50446.50), the info is in field1

'Col1' Endpoint[442] 'DO' Wallet[501] 'Trilogy' Balance '50446.50 USD'

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@edfigue88 

Try this run anywhere example which shows your data and the necessary rex

| makeresults
| eval field1="'Col1' Endpoint[442] 'DO' Wallet[501] 'Trilogy' Balance '50446.50 USD'"
| rex field=field1 "Balance\s'(?<Balance>[\d\.]+)"

 Hope this helps

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

@edfigue88 

Try this run anywhere example which shows your data and the necessary rex

| makeresults
| eval field1="'Col1' Endpoint[442] 'DO' Wallet[501] 'Trilogy' Balance '50446.50 USD'"
| rex field=field1 "Balance\s'(?<Balance>[\d\.]+)"

 Hope this helps

 

edfigue88
Explorer

@bowesmana can you help me with this change please

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The regex101 is a good way to learn and play with regex

https://regex101.com/

 

edfigue88
Explorer

Yes, that work for me, if I want to have the "USD" in my results, what I need to change or include?

0 Karma

bowesmana
SplunkTrust
SplunkTrust

You can either extract the currency as a separate field, like this

| makeresults
| eval field1="'Col1' Endpoint[442] 'DO' Wallet[501] 'Trilogy' Balance '50446.50 USD'"
| rex field=field1 "Balance\s'(?<Balance>[\d\.]+)\s(?<Currency>\w+)"
| eval Amount=Balance." ".Currency

and then you have Balance and Currency, which you can then join together again if you need, or you can extract it as part of the original Balance field like this

| rex field=field1 "Balance\s'(?<Balance>[\d\.]+\s\w+)"

The benefit of using the former approach is you can then use the numeric balance field if you want to make calculations, whereas with the currency as part of the field, you cannot.

 

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...