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!

What the End of Support for Splunk Add-on Builder Means for You

Hello Splunk Community! We want to share an important update regarding the future of the Splunk Add-on Builder ...

Solve, Learn, Repeat: New Puzzle Channel Now Live

Welcome to the Splunk Puzzle PlaygroundIf you are anything like me, you love to solve problems, and what ...

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...