Splunk Search

regex to get xml (Element Name + Value)

sbsbb
Builder

I have a xml-field with two different Elements :


...


...

I wanted to extract the 2 Elements, but also knowing after extract, where the info is coming form.

If I make something like that :
<(Element1|Element2)\b[^>]>(?P.)</(Element1|Element2)

Then I have the multivalued element "element", but I don't know it the data in it, is form Element1 or 2

Is it possible to have regex extracting the whole element with tag ? like
element= ...
...

Tags (3)
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

If you want to include the tags in your field value you just need to move them into the parentheses and make sure the closing tags don't get greedily overlooked:

(?P<element><element[12]\b[^>]*>.*?</element[12]>)

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

If you want to include the tags in your field value you just need to move them into the parentheses and make sure the closing tags don't get greedily overlooked:

(?P<element><element[12]\b[^>]*>.*?</element[12]>)

sbsbb
Builder

It works, many thanks !

Because the element Name is complete different, I've adapted your answer to

(?P<(element1|element2)\b[^>]>.?</(element1|element2)>)

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