<?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 Regex to return text over multiple lines in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355474#M105203</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am trying to extract several lines of text using regex and whilst I can extract up to the first carriage return I cannot work out how to extract the subsequent line&lt;/P&gt;

&lt;P&gt;The below is the text I am attempting to extract&lt;BR /&gt;
[29/07/17 23:33:22:707 EST] 0000003e SystemOut     O 23:33:22.707 [WebContainer : 4] ERROR c.a.r.l.controller.NotifyController - OOps&lt;BR /&gt;
javax.xml.ws.soap.SOAPFaultException: Failed to process response headers&lt;/P&gt;

&lt;P&gt;And the regex I am using is&lt;BR /&gt;
    rex "[.*?(?P&lt;ERR&gt;[^\r\n]+)"&lt;/ERR&gt;&lt;/P&gt;

&lt;P&gt;The output using the above is&lt;BR /&gt;
[29/07/17 23:33:22:707 EST] 0000003e SystemOut     O 23:33:22.707 [WebContainer : 4] ERROR c.a.r.l.controller.NotifyController - OOps&lt;/P&gt;

&lt;P&gt;How can I expand the above regex to capture the second line (javax.xml.ws.soap.SOAPFaultException: Failed to process response headers) ?&lt;/P&gt;

&lt;P&gt;Help will be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Alastair&lt;/P&gt;</description>
    <pubDate>Wed, 09 Aug 2017 05:20:22 GMT</pubDate>
    <dc:creator>ahogbin</dc:creator>
    <dc:date>2017-08-09T05:20:22Z</dc:date>
    <item>
      <title>Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355474#M105203</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am trying to extract several lines of text using regex and whilst I can extract up to the first carriage return I cannot work out how to extract the subsequent line&lt;/P&gt;

&lt;P&gt;The below is the text I am attempting to extract&lt;BR /&gt;
[29/07/17 23:33:22:707 EST] 0000003e SystemOut     O 23:33:22.707 [WebContainer : 4] ERROR c.a.r.l.controller.NotifyController - OOps&lt;BR /&gt;
javax.xml.ws.soap.SOAPFaultException: Failed to process response headers&lt;/P&gt;

&lt;P&gt;And the regex I am using is&lt;BR /&gt;
    rex "[.*?(?P&lt;ERR&gt;[^\r\n]+)"&lt;/ERR&gt;&lt;/P&gt;

&lt;P&gt;The output using the above is&lt;BR /&gt;
[29/07/17 23:33:22:707 EST] 0000003e SystemOut     O 23:33:22.707 [WebContainer : 4] ERROR c.a.r.l.controller.NotifyController - OOps&lt;/P&gt;

&lt;P&gt;How can I expand the above regex to capture the second line (javax.xml.ws.soap.SOAPFaultException: Failed to process response headers) ?&lt;/P&gt;

&lt;P&gt;Help will be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Alastair&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 05:20:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355474#M105203</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2017-08-09T05:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355475#M105204</link>
      <description>&lt;P&gt;@ahogbin you would need to paste your rex command again with the code button (101010) selected so that special characters do not escape.&lt;/P&gt;

&lt;P&gt;From your question your intent is not very clear. You have pasted your event example and you are asking to extract the entire content using rex? Ideally you should define a pattern match/substring within main string. You would need to define regular expression flag to &lt;CODE&gt;(?ms)&lt;/CODE&gt; to have Dot &lt;CODE&gt;(.)&lt;/CODE&gt; match newline character as well. &lt;CODE&gt;s&lt;/CODE&gt; flag ensures that dot matches newline character as well. Where m=&amp;gt; multiline and s=&amp;gt;singleline (Read reference details on regex101.com for the same.&lt;/P&gt;

&lt;P&gt;PS: Since I do not have clarity following is just an example for showing syntax (however, do not consider this as your final query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=_raw "(?ms)(?&amp;lt;ExtractedData&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For us to assist you better, please clarify what substring you need to extract and what is your current regular expression.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 05:59:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355475#M105204</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-09T05:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355476#M105205</link>
      <description>&lt;P&gt;I assume you want the 3 lines starting with a timestamp, so i would use&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;[\d{2}\/\d{2}\/\d{2}\ (.*?[\r\n]){3}&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 09 Aug 2017 06:34:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355476#M105205</guid>
      <dc:creator>FritzWittwer_ol</dc:creator>
      <dc:date>2017-08-09T06:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355477#M105206</link>
      <description>&lt;P&gt;You need to prefix your RegEx with &lt;CODE&gt;(?ms)&lt;/CODE&gt; which will cause the &lt;CODE&gt;.&lt;/CODE&gt; token to include &lt;CODE&gt;[\r\n]&lt;/CODE&gt; and also to process multi-line.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 11:28:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355477#M105206</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-09T11:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355478#M105207</link>
      <description>&lt;P&gt;Hello...&lt;BR /&gt;
Thanks for the advice.. I have tried the various options below but none allow me to progress past retrieving the first 2 lines&lt;/P&gt;

&lt;P&gt;[29/07/17 23:33:22:707 EST] 0000003e SystemOut O 23:33:22.707 [WebContainer : 4] ERROR c.a.r.l.controller.NotifyController - OOps&lt;/P&gt;

&lt;P&gt;The whole string I am trying to extract is&lt;BR /&gt;
[29/07/17 23:33:22:707 EST] 0000003e SystemOut O 23:33:22.707 [WebContainer : 4] ERROR c.a.r.l.controller.NotifyController - OOps&lt;BR /&gt;
javax.xml.ws.soap.SOAPFaultException: Failed to process response headers&lt;/P&gt;

&lt;P&gt;Regex I am using is &lt;CODE&gt;rex field=_raw "(?ms)\[.*?(?P&amp;lt;ERR&amp;gt;[^\r\n]+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I know I am missing something but just cannot figure out what.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Alastair&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 21:47:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355478#M105207</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2017-08-09T21:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355479#M105208</link>
      <description>&lt;P&gt;It should actually be as following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=_raw "(?ms)(?&amp;lt;ERR&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here Dot will also match newline charatcer i.e. &lt;CODE&gt;\n\r&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Alternative you can also try the following to see whether it is newline character(\n\r) or something else:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval rawWithoutNewLine=replace(_raw,"\n\r"," ")
| rex field=rawWithoutNewLine "(?ms)(?&amp;lt;ERR&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Aug 2017 02:36:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355479#M105208</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-10T02:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355480#M105209</link>
      <description>&lt;P&gt;Still not working... I am now just getting the entire output that spans many lines when I really just want to get the first 3 (well the first 2 really as the first line wraps)&lt;/P&gt;

&lt;P&gt;[29/07/17 23:33:22:707 EST] 0000003e SystemOut     O 23:33:22.707 [WebContainer : 4] ERROR c.a.r.l.controller.NotifyController - OOps&lt;BR /&gt;
javax.xml.ws.soap.SOAPFaultException: Failed to process response headers&lt;BR /&gt;
... 31 lines omitted ...&lt;/P&gt;

&lt;P&gt;The regex I was using stops at the first return (after the word OOps. How do I get it to also include the second line and then stop at the end of line (javax.xml.ws.soap.SOAPFaultException: Failed to process response headers) ?&lt;/P&gt;

&lt;P&gt;The provide regex (and thank you for this) also picks up the 31 omitted lines.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 03:31:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355480#M105209</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2017-08-10T03:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355481#M105210</link>
      <description>&lt;P&gt;I think I see the issue. The second part of the string is not terminated by a carriage return / new lines and looks to just continue on&lt;/P&gt;

&lt;P&gt;13/07/17 23:07:44:186 EST] 00000040 SystemOut O 23:07:44.185 [WebContainer : 8] ERROR c.a.r.l.controller.NotifyController - OOps javax.xml.ws.soap.SOAPFaultException: Failed to process response headers at org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.createSystemException(MethodMarshallerUtils.java:1363) ~[org.apache.axis2.jar:na] at org.apache.axis2.jaxws.marshaller.impl.alt.&lt;/P&gt;

&lt;P&gt;This explains why I am getting the full output rather than stopping at the first 'at'&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 04:04:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355481#M105210</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2017-08-10T04:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355482#M105211</link>
      <description>&lt;P&gt;worked out the solution.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "(?ms)(?P&amp;lt;ERR&amp;gt;^.*?(?=at))"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives me all lines up the , but not including, the first 'at'&lt;/P&gt;

&lt;P&gt;Thanks for the pointers and suggestions.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 22:18:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355482#M105211</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2017-08-10T22:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to return text over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355483#M105212</link>
      <description>&lt;P&gt;Don't forget to upvote the helpful homies.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 01:59:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-return-text-over-multiple-lines/m-p/355483#M105212</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-11T01:59:47Z</dc:date>
    </item>
  </channel>
</rss>

