Splunk Search

Multiline regex capture and newlines

kevintelford
Path Finder

Kevins back with more corner cases!

So, I have events that will look something like

key1=value1
key2=value2
key3=value3
key4=value4
key5=value5
something
  the
  cake
  is
  a
  lie
--------------------------

or like this

key1=value1
key2=value2
key3=value3
key4=value4
key5=value5
something : 
  something else
  funny

So the kv pairs are taken care of, but I'd like to create a new event for my list of "somethings". But there could be any number of them, they could contain any characters, and there sometimes could be a line of dashes at the end. I thought about originally removing the dash lines altogether with the SEDCMD but they're the only consistent thing I can break events on.

So a regex that works on the search path is

| rex field=_raw "something\s*:\s(?s)(?<something_list>.*)"

and in a transforms.conf

REGEX = something\s*:\s(?s)(?<something_list>.*)

but the problem is it included the dashed lines.

So I tried this on the search path

| rex field=_raw "something\s*:\s(?s)(?<something_list>.*?)(:?\n-|$)"

Which worked, but when I put it in the transforms it did NOT work.

Now, when I was getting the value "something_list" the first thing I noticed is that all of my caputured values were getting munged. So the first regex would produce something_list=thecakeisalie-------------------------- and the second something_list=thecakeisalie. But then the second would only work from the search command and not my transforms and I'm wondering if perhaps newlines, in regexes and event creation, cause something wacky to happen inside of Splunk?

Thanks, Kevin

Tags (2)

fk319
Builder

I was gogling and found your question.

I was able to get a '.' to match everything by '(.|\r)'.

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...