Splunk Search

Regex match till end of event?

Cuyose
Builder

Not sure why I cant find this, but the following is not working.

|rex field=_raw "(?i)response=(?<responseXML>.+)$"

where response= occurs somewhere in the event and always continues to the very end of a multi lined event.

Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

 | rex field=_raw "response=(?<responseXML>[\S\s\r\n]*)$"

Option 2

 your base search | eval responseXML=replace(_raw,"^([\S\s\r\n]*)response=","")

View solution in original post

0 Karma

Richfez
SplunkTrust
SplunkTrust

Do you have a sample of one of the difficult, long, multi-line event that we can use for confirmation of potential solutions before posting them?

0 Karma

inventsekar
SplunkTrust
SplunkTrust

we are trying to create the rex query with just our own understanding of your issue.
could you please update us an event, and your current query, please.

0 Karma

somesoni2
Revered Legend

Give this a try

 | rex field=_raw "response=(?<responseXML>[\S\s\r\n]*)$"

Option 2

 your base search | eval responseXML=replace(_raw,"^([\S\s\r\n]*)response=","")
0 Karma

Cuyose
Builder

Cool, this worked(Option 1), but its very odd that I had to resort to this, as the first example I tried had worked in many other situations!

0 Karma

dbcase
Motivator

Have you tried erex?

http://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Erex

Using erex, Splunk will attempt to write the rex pattern for you given your example string(s).

0 Karma

Cuyose
Builder

Unfortunately, while useful for smaller more specific examples, this cannot take multiple 1000 character examples across multiple lines as input.

0 Karma

sundareshr
Legend

Try this

| rex field=_raw "response=(?<msg>[^\t\n]+)"
0 Karma

Cuyose
Builder

this does not work because it only captures to the end of the current line the response= is found in.

0 Karma

sundareshr
Legend

Try this

| rex field=_raw "response=(?<msg>[^\S\t\r\n]+)"
0 Karma

inventsekar
SplunkTrust
SplunkTrust

"(?i)response=(?.+)$" -----

- you should use < and > around the variable - (?<i>) 
- (?<i>) needs to come where it will appear on the event (ie, after the "response=")

and i created few sample events ending with "response=digits"

event 1 - Extract "from" and "to" fields using regular expressions. response=101
event 2 - If a raw event contains "From: Susan To: Bob", then from=Susan and to=Bob, response=404
event 3 - source="tutorialdata.zip:./www1/access.log" response=500

and this query picks up the response codes fine.

sourcetype=responseREX | rex field=_raw "response=(?<i>.*)" | table _raw, i 

regarding the end of line $, these below two works same -
response=(?.)
and
response=(?.
)$

0 Karma

Cuyose
Builder

This only captured the first character after response=

0 Karma

Cuyose
Builder

Sorry, I had that, but I must have missed the code button and it stripped out some things.

This is not working

|rex field=_raw "(?m)Data=(?<xmlData>.+)$"
0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...