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!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...