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!

What’s new on Splunk Lantern in August

This month’s Splunk Lantern update gives you the low-down on all of the articles we’ve published over the past ...

Welcome to the Future of Data Search & Exploration

You have more data coming at you than ever before. Over the next five years, the total amount of digital data ...

This Week's Community Digest - Splunk Community Happenings [8.3.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...