Splunk Search

Regex - Capture group without duplicating value

ben_leung
Builder

This is my string

<search>1</search> <search>4</search> <search>2</search> <search>5</search> <search>3</search> <search>6</search>

I have the following rex command rex field=a_field "<search>(?<TESTING>(.?))</search>"
This will only grab TESTING=1. I want to grab all the values.

Using the rex command rex field=a_field "<search>(?<TESTING>.*)</search>"
will grab everything in-between, including the brackets and search string.

How would I make sure that I only grab the values between the bracketed strings?

Tags (2)
0 Karma

twinspop
Influencer

max_match:

| rex field=foo max_match=99 ....

Unless I'm misunderstanding the question

martin_mueller
SplunkTrust
SplunkTrust

Additionally, take a look at non-greedy matching in regex. This will greedily match everything until the last closing tag:

<search>(?<TESTING>.*)</search>

While this will non-greedily match only the bit until the first closing tag:

<search>(?<TESTING>.*?)</search>

Note the question mark after the asterisk.

0 Karma

ben_leung
Builder

Perfect! Thank you for this parameter for the rex command.

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 ...