Splunk Search

Regex assistance on match, capture, repeat - simple yet I can't!

Barty
Explorer

Good morning you lovely lot,

I have a theoretically simple regex extraction, but it is slaying me. If one of you would be so kind as to assist, it would be greatly appreciated. You'll see below the event that the extraction is required from. Essentially, we require to capture the 'role(s)' that a user may have. The opening tag is and then the role itself is contained within . The issue is that is used throughout the events and also that a user may have one, or multiple roles. As such, the regex requires to capture the first role found after and then subsequently each other role if found before terminating on .

I've gotten close-ish, but cannot capture each role individually, instead either the first, last or ALL values between the tags of 'items'. Please help as it's absolutely ending me - I'm not exactly great with regex as it's all fairly new to me.

Event Sample:

/><jobtitle>Digital Content</jobtitle><emarketingoptout /><contactpref /><roles><item>INVEST_IFA</item><item>PROTECT_IFA</item><item>RS_IFA</item><item>SOLICITOR</item></roles><permissions><item>INVEST_APPS</item><item>PROTECT_APPS</item><item>RS_APPS</item><item>SOL_APPS</item><item>UPDATE_PROFILE</item>

Regex so far (awful I know):

All Items:

`(<item>(?<role>[\w]*)\<\/item>+?)`

First or last depending upon greed:

`[\w\W]+((<item>+(?<role>[\w]*)\<\/item>)+)<\/roles`
Tags (2)
0 Karma
1 Solution

to4kawa
Ultra Champion
....
| rex "roles\>(?<rolesfield>.*)\<\/roles\>"
| rex field=rolesfield max_match=0 "\>(?<roles>[A-Z_]+)\<"

View solution in original post

0 Karma

to4kawa
Ultra Champion
....
| rex "roles\>(?<rolesfield>.*)\<\/roles\>"
| rex field=rolesfield max_match=0 "\>(?<roles>[A-Z_]+)\<"
0 Karma

Barty
Explorer

Thank you for the response to4kawa, however is there no means to do this within a single regex extraction??

0 Karma

to4kawa
Ultra Champion

why? two REGEX is easy to understand and simple.

0 Karma

Barty
Explorer

I appreciate that, I simply wondered if there was a means to achieve this via one regex extraction. Thank you for the assistance none the less.

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