Splunk Search

Regex a value

timyong80
Explorer

Hello,

I have multiple values for a field in my search results and they look like the ones below. Can you show me the condition to regex the second value so that it becomes "aks-nodes-15133334-vmss" without the trailing numbers after vmss? At the same time, I would like to maintain value 1 as it is since it doesn't have "vmss" in the trailing name. So, if the value contains vmss, remove the trailing numbers but if there's no vmss in the value, let the value remains at it is.

Before

1) aks-agentpool-60893500-2
2) aks-nodes-15133334-vmss000002

After

1) aks-agentpool-60893500-2
2) aks-nodes-15133334-vmss

If I do this (?<host>.+\D), it will make item 2 looks like aks-nodes-15133334-vmss but it makes item 1 looks like aks-agentpool-60893500-

Thank you for your help.

Labels (1)
0 Karma

renjith_nair
Legend

Try

(?<host>.*(vms)?\D)
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

timyong80
Explorer

Thanks. It works for no.2 but for no.1, it regex the value as "aks-agentpool-60893500-" (without the 2).

0 Karma

renjith_nair
Legend

Apologies, for some reason it was working fine in regex101

https://regex101.com/r/Wlrjiv/1

Try another version - tested in Splunk

| makeresults |eval hosts="aks-agentpool-60893500-2 aks-nodes-15133334-vmss000002"|makemv hosts|mvexpand hosts
|rex field=hosts "(?<host>.*(?=vmss)\D+|.+)"

 

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...

Edge Processor Scaling, Energy & Manufacturing Use Cases, and More New Articles on ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Get More Out of Your Security Practice With a SIEM

Get More Out of Your Security Practice With a SIEMWednesday, July 31, 2024  |  11AM PT / 2PM ETREGISTER ...