Splunk Search

How to write regex to represent only first part of value?

mark_groenveld
Path Finder

I have a key:value for db names but need only the first part.

Example

Current
DBNAME : db001_inst1:schemanamexyx
Or
DBNAME : db01_inst1:schemanamexyx

Requested
REX statement to provide only the values in front of the colon.  I.E., db001_inst1 or db01_inst1

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

It would help to know what you've tried already.

Try this

| rex field=db_name "(?<key>[^:]+)"

Be sure to change "db_name" to name of the field containing the key:value.  Don't use _raw or this won't work.

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

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mark_groenveld,

you could try this regex

| rex ":\s+(?<your_field>[^:]+)"

that you can test at https://regex101.com/r/pj1bQO/1

Ciao.

Giuseppe

0 Karma

richgalloway
SplunkTrust
SplunkTrust

It would help to know what you've tried already.

Try this

| rex field=db_name "(?<key>[^:]+)"

Be sure to change "db_name" to name of the field containing the key:value.  Don't use _raw or this won't work.

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

mark_groenveld
Path Finder

Thanks Rich for the solution.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mark_groenveld,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma
Get Updates on the Splunk Community!

AppDynamics Summer Webinars

This summer, our mighty AppDynamics team is cooking up some delicious content on YouTube Live to satiate your ...

SOCin’ it to you at Splunk University

Splunk University is expanding its instructor-led learning portfolio with dedicated Security tracks at .conf25 ...

Credit Card Data Protection & PCI Compliance with Splunk Edge Processor

Organizations handling credit card transactions know that PCI DSS compliance is both critical and complex. The ...