Splunk Search

How to use the DOTALL option in a regular expression

tsingara
Engager

I'm running a regular expression on a string which runs for 5 or more lines. The first few words on the first line helps me determine if the rest of the sentence is useful for me.

rex "(?P<Application>\w+[a-zA-Z]*) (?P<Message>.*+)" | fields Application, Message | Search Application ="abc"

here I want to display results if my Application equates to "abc" which is at the beginning of my multi-line string, the Message variable has only the characters till the end of the first line, it does return characters from the second or third line

Search String

abc def

ghi

jkl

The Application variable equates "abc" and Message return only "def", but I want it to return "def ghi jkl".

How should the Regular expression be changed to achieve this?

Tags (1)
0 Karma
1 Solution

ahall_splunk
Splunk Employee
Splunk Employee

The correct nomenclature is to add (?ms) on the beginning - the s is dotall, and the m is multi-line. Thus:

rex field=_raw "(?ms)(?P<Application>\w+) (?P<Message>.*+)"

View solution in original post

ahall_splunk
Splunk Employee
Splunk Employee

The correct nomenclature is to add (?ms) on the beginning - the s is dotall, and the m is multi-line. Thus:

rex field=_raw "(?ms)(?P<Application>\w+) (?P<Message>.*+)"
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...