<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Regex for multiline events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55556#M13556</link>
    <description>&lt;P&gt;I'll admit I don't know why (?m) doesn't seem to work in your case - it should! Your second example could possibly work anyway if you changed the regex a bit - right now you're performing a greedy match so the regex will match as much as it possibly can. You need to change it to a non-greedy version by adding a ? at the end. Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-ipaddress = (?m)^IPADDRESS: (?P&amp;lt;ipaddress&amp;gt;.+?)[\r\n]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Jan 2012 09:41:09 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2012-01-20T09:41:09Z</dc:date>
    <item>
      <title>Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55553#M13553</link>
      <description>&lt;P&gt;How do I configure regex to get only test after each line's &lt;FIELDNAME&gt;: &lt;VALUE&gt; in the following log?&lt;/VALUE&gt;&lt;/FIELDNAME&gt;&lt;/P&gt;

&lt;P&gt;I have a log file containing events like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;PID: 3047
CurrentTime: 2012/01/20 16:23:55
Username: username45
Floor: floor7
IPADDRESS: 10.1.1.4
Result: success
CurrentTime: 2012/01/20 16:23:54
Username: username51
Floor: floor3
IPADDRESS: 10.1.1.32
Result: fail
PID: 8020
CurrentTime: 2012/01/20 16:23:53
Username: username67
Floor: floor8
IPADDRESS: 10.1.1.24
Result: success
Additional: Some more information
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and props.conf includes the following configuraion.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[mytype]
SHOULD_LINEMERGE = true
BREAK_ONLY_BEFORE = ^PID:
EXTRACT-result = ^Result: (?P&amp;lt;result&amp;gt;.+)$
EXTRACT-ipaddress = ^IPADDRESS: (?P&amp;lt;ipaddress&amp;gt;.+)$
EXTRACT-floor = ^Floor: (?P&amp;lt;floor&amp;gt;.+)$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In order to get value sucha as floor8 for floor and 10.1.1.24 for ipaddress after :,&lt;BR /&gt;
I ran the search for each field, but still getting unwanted information too.&lt;/P&gt;

&lt;P&gt;sourcetype="mytype" | table result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    result
--- ----------------------------------------
1   success
2   fail PID: 9360
3   fail PID: 6634
4   fail PID: 3908
5   fail PID: 1183
6   success PID: 8456
7   success PID: 5730
8   fail PID: 3004
9   fail PID: 278
10  fail PID: 7551
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;sourcetype="mytype" | table result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ipaddress
--- ----------------------------------------
1   10.1.1.21 Result: success
2   10.1.1.34 Result: fail PID: 9360
3   10.1.1.9 Result: fail PID: 6634
4   10.1.1.21 Result: fail PID: 3908
5   10.1.1.33 Result: fail PID: 1183
6   10.1.1.8 Result: success PID: 8456
7   10.1.1.20 Result: success PID: 5730
8   10.1.1.32 Result: fail PID: 3004
9   10.1.1.8 Result: fail PID: 278
10  10.1.1.20 Result: fail PID: 7551
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;sourcetype="mytype" | table result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    floor
--- ----------------------------------------
1   floor7 IPADDRESS: 10.1.1.21 Result: success
2   floor1 IPADDRESS: 10.1.1.34 Result: fail PID: 9360
3   floor5 IPADDRESS: 10.1.1.9 Result: fail PID: 6634
4   floor9 IPADDRESS: 10.1.1.21 Result: fail PID: 3908
5   floor3 IPADDRESS: 10.1.1.33 Result: fail PID: 1183
6   floor8 IPADDRESS: 10.1.1.8 Result: success PID: 8456
7   floor2 IPADDRESS: 10.1.1.20 Result: success PID: 5730
8   floor6 IPADDRESS: 10.1.1.32 Result: fail PID: 3004
9   floor0 IPADDRESS: 10.1.1.8 Result: fail PID: 278
10  floor4 IPADDRESS: 10.1.1.20 Result: fail PID: 7551
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I configure regex in props.conf to get only test after each line's &lt;FIELDNAME&gt;: &lt;VALUE&gt;?&lt;/VALUE&gt;&lt;/FIELDNAME&gt;&lt;/P&gt;

&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2012 08:25:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55553#M13553</guid>
      <dc:creator>melonman</dc:creator>
      <dc:date>2012-01-20T08:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55554#M13554</link>
      <description>&lt;P&gt;You need to activate multi-line mode matching for the regex by specifying (?m) at the start. Like this for instance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-ipaddress = (?m)^IPADDRESS: (?P&amp;lt;ipaddress&amp;gt;.+)$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;More information on multi-line mode matching in regular expressions: &lt;BR /&gt;&lt;BR /&gt;
&lt;A href="http://www.regular-expressions.info/modifiers.html"&gt;http://www.regular-expressions.info/modifiers.html&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;
&lt;A href="http://www.regular-expressions.info/anchors.html"&gt;http://www.regular-expressions.info/anchors.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2012 08:43:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55554#M13554</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-01-20T08:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55555#M13555</link>
      <description>&lt;P&gt;Thanks, I tried to change to multi-line mode, but still no luck. &lt;/P&gt;

&lt;P&gt;With EXTRACT-ipaddress = (?m)^IPADDRESS: (?P&lt;IPADDRESS&gt;.+)$,&lt;BR /&gt;
"sourcetype="mytype" | head 1 | table ipaddress" still returns:&lt;/IPADDRESS&gt;&lt;/P&gt;

&lt;P&gt;1  10.1.1.21 Result: success&lt;BR /&gt;
2  10.1.1.34 Result: fail PID: 9360&lt;BR /&gt;
3  10.1.1.9 Result: fail PID: 663410.1.1.21 Result: success&lt;/P&gt;

&lt;P&gt;With EXTRACT-ipaddress = (?m)^IPADDRESS: (?P&lt;IPADDRESS&gt;.+)[\r\n],&lt;BR /&gt;
"sourcetype="mytype" | head 1 | table ipaddress" still returns:&lt;/IPADDRESS&gt;&lt;/P&gt;

&lt;P&gt;1  10.1.1.21&lt;BR /&gt;
2  10.1.1.34 Result: fail&lt;BR /&gt;
3  10.1.1.9 Result: fail&lt;/P&gt;

&lt;P&gt;While I am reading the regex website, I would like to know how to get this right.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2012 09:25:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55555#M13555</guid>
      <dc:creator>melonman</dc:creator>
      <dc:date>2012-01-20T09:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55556#M13556</link>
      <description>&lt;P&gt;I'll admit I don't know why (?m) doesn't seem to work in your case - it should! Your second example could possibly work anyway if you changed the regex a bit - right now you're performing a greedy match so the regex will match as much as it possibly can. You need to change it to a non-greedy version by adding a ? at the end. Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-ipaddress = (?m)^IPADDRESS: (?P&amp;lt;ipaddress&amp;gt;.+?)[\r\n]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2012 09:41:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55556#M13556</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-01-20T09:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55557#M13557</link>
      <description>&lt;P&gt;Yes Ayn is correct.  The non-greedy match fixes it although you should not need it.  This config works for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[mytype]
SHOULD_LINEMERGE = true
BREAK_ONLY_BEFORE = ^CurrentTime:
EXTRACT-result = ^(?m)Result: (?P&amp;lt;result&amp;gt;.+?)$
EXTRACT-ipaddress = ^(?m)IPADDRESS: (?P&amp;lt;ipaddress&amp;gt;.+?)$
EXTRACT-floor = ^(?m)Floor: (?P&amp;lt;floor&amp;gt;.+?)$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;BUT, so does this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[mytype]
SHOULD_LINEMERGE = true
BREAK_ONLY_BEFORE = ^CurrentTime:
EXTRACT-result = ^(?m-s)Result: (?P&amp;lt;result&amp;gt;.+)$
EXTRACT-ipaddress = ^(?m-s)IPADDRESS: (?P&amp;lt;ipaddress&amp;gt;.+)$
EXTRACT-floor = ^(?m-s)Floor: (?P&amp;lt;floor&amp;gt;.+)$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem appears to be that the 's' modifier is 'on' by default!  It should not be if we're using PCRE.&lt;BR /&gt;
The 's' modifier says that the '.' character will also match newline characters (i.e. \r or \n).&lt;BR /&gt;
The first config above works because we are saying do a non-greedy match.&lt;BR /&gt;
The second config above works because we are saying do not allow the '.' to match a newline char.&lt;/P&gt;

&lt;P&gt;For some reason Splunk is behaving as though we had said (?sm).  Anyway we have a fix!&lt;/P&gt;

&lt;P&gt;Note I changed the BREAK_ONLY_BEFORE because the PID does not appear in every record.&lt;/P&gt;

&lt;P&gt;Ayn solved your problem, I'm just clarifying was it didn't work.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:20:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55557#M13557</guid>
      <dc:creator>itinney</dc:creator>
      <dc:date>2020-09-28T10:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55558#M13558</link>
      <description>&lt;P&gt;Thank you for your help!&lt;BR /&gt;
Now I can get what I wanted. I added "?" as you pointed out.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2012 04:20:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55558#M13558</guid>
      <dc:creator>melonman</dc:creator>
      <dc:date>2012-01-21T04:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55559#M13559</link>
      <description>&lt;P&gt;Thanks for helpful comment!&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2012 04:22:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55559#M13559</guid>
      <dc:creator>melonman</dc:creator>
      <dc:date>2012-01-21T04:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55560#M13560</link>
      <description>&lt;P&gt;Huge +1 for the "s" modifier.  It had me stuck &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2013 02:27:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55560#M13560</guid>
      <dc:creator>markmcd</dc:creator>
      <dc:date>2013-08-09T02:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55561#M13561</link>
      <description>&lt;P&gt;Just another huge +1 for the -s.   Very helpful.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 16:31:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55561#M13561</guid>
      <dc:creator>nzambo_splunk</dc:creator>
      <dc:date>2017-03-21T16:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for multiline events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55562#M13562</link>
      <description>&lt;P&gt;We have Splunk Enterprise 7.0.0.&lt;/P&gt;

&lt;P&gt;I have a multiline event I am trying to configure a sourcetype for and was able to successfully test using regex101.com but I do not get the results in Splunk when setting up the sourcetype.&lt;/P&gt;

&lt;P&gt;This example log has 400+ lines. I know the word to start and the word to end the match for the event. I just need to match the lines started with &lt;STRONG&gt;PRPM&lt;/STRONG&gt; down to the line with the word &lt;STRONG&gt;END&lt;/STRONG&gt;. I should also note that I had to add the MAX_EVENTS due to the length of the event data.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;BR /&gt;
PRPM*28 blah blah blah blah blah&lt;BR /&gt;
blah blah blah&lt;BR /&gt;
blah ........blah&lt;BR /&gt;
blah blah&lt;BR /&gt;
....&lt;BR /&gt;
..blah blah&lt;BR /&gt;
END&lt;/P&gt;

&lt;P&gt;This works on REGEX101.com but not in Splunk. &lt;CODE&gt;(?s)^PRPM(.*?END)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I also tried with (?m). Suggestions?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 23:56:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-multiline-events/m-p/55562#M13562</guid>
      <dc:creator>hexxamillion</dc:creator>
      <dc:date>2017-10-31T23:56:51Z</dc:date>
    </item>
  </channel>
</rss>

