Splunk Search

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

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

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

View solution in original post

0 Karma

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

View solution in original post

0 Karma

Explorer

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

0 Karma

Ultra Champion

why? two REGEX is easy to understand and simple.

0 Karma

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