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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...