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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...