Splunk Search

regex extracting between xml tags and quotes

exocore123
Path Finder
<fin:Data namespace=\"url1\" type=\"EData\">...

Using
basic search | rex "Data\snamespace=\"(?P<preName>[^\"]+)\"" | stats count by preName is empty

Error here
basic search | rex "Data\snamespace=\\\"(?P<preName>[^\\]+)\\\"" | stats count by preName

I am not sure what's wrong, no results found. I am trying to get url1 using the regex above, but it's not matching? I am trying to see the list of values for that particular tag

0 Karma
1 Solution

somesoni2
Revered Legend

Try like this

basic search | rex "Data\snamespace=[^\"]+\"(?P<preName>[^\"]+)\"" | stats count by preName

View solution in original post

0 Karma

woodcock
Esteemed Legend

You need this:

| makeresults | eval _raw="...
...<fin:Data namespace=\\\"url1\\\" type=\\\"EData\\\">..."
| rex "Data\snamespace=\\\\\"(?<preName>[^\\\"]+)\\\\\""

somesoni2
Revered Legend

Try like this

basic search | rex "Data\snamespace=[^\"]+\"(?P<preName>[^\"]+)\"" | stats count by preName
0 Karma

exocore123
Path Finder

Care to explain? I also still have "\" at the end, are we just matching until we see quotations?

0 Karma

somesoni2
Revered Legend

That's correct. after namespace= match till next double quotes (avoiding escaped backward slash altogether). Rest is same as your's.

0 Karma
Get Updates on the Splunk Community!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...