<?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: rex over multiple lines in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178975#M51510</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;
no, I've appended only the search part in front, place your rex line and appended teh tabel formatting. What do you mean with does not match the previous data?&lt;/P&gt;</description>
    <pubDate>Tue, 12 Aug 2014 12:48:41 GMT</pubDate>
    <dc:creator>tbasima1</dc:creator>
    <dc:date>2014-08-12T12:48:41Z</dc:date>
    <item>
      <title>rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178970#M51505</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;

&lt;P&gt;hope to find here some help.&lt;BR /&gt;
I've tried now several things including searching in the answers here but don't find the solution.&lt;/P&gt;

&lt;P&gt;I've for example a log file that is structured like that&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;BR /&gt;
&amp;lt;PublishLog Version="5.0"&amp;gt;&lt;BR /&gt;
   &amp;lt;RequestReport&amp;gt;&lt;BR /&gt;
      &amp;lt;Request&amp;gt;&lt;BR /&gt;
         &amp;lt;Id&amp;gt;Z00000hyjlq1l4Xpa3Z53MZbem7cZ&amp;lt;/Id&amp;gt;&lt;BR /&gt;
         &amp;lt;StartTime&amp;gt;1407386816620&amp;lt;/StartTime&amp;gt;&lt;BR /&gt;
         &amp;lt;User&amp;gt;cli@ss001500.tauri.ch&amp;lt;/User&amp;gt;&lt;BR /&gt;
         &amp;lt;Type&amp;gt;ps_publish&amp;lt;/Type&amp;gt;&lt;BR /&gt;
         &amp;lt;RequestTime&amp;gt;1407386816587&amp;lt;/RequestTime&amp;gt;&lt;BR /&gt;
         &amp;lt;RequestMsg/&amp;gt;&lt;BR /&gt;
         &amp;lt;Description&amp;gt;cli for user cli@ss001500.tauri.ch&amp;lt;/Description&amp;gt;&lt;BR /&gt;
         &amp;lt;ClientData/&amp;gt;&lt;BR /&gt;
         &amp;lt;Result&amp;gt;FLR&amp;lt;/Result&amp;gt;&lt;BR /&gt;
         &amp;lt;EndTime&amp;gt;1407387275454&amp;lt;/EndTime&amp;gt;&lt;BR /&gt;
      &amp;lt;/Request&amp;gt;&lt;BR /&gt;
      &amp;lt;Replies&amp;gt;&lt;BR /&gt;
         &amp;lt;ReplyFirst&amp;gt;&lt;BR /&gt;
            &amp;lt;Time&amp;gt;1407386816719&amp;lt;/Time&amp;gt;&lt;BR /&gt;
            &amp;lt;Result&amp;gt;ACK&amp;lt;/Result&amp;gt;&lt;BR /&gt;
            &amp;lt;RequestId&amp;gt;Z00000hyjlq1l4Xpa3Z53MZbem7cZ&amp;lt;/RequestId&amp;gt;&lt;BR /&gt;
         &amp;lt;/ReplyFirst&amp;gt;&lt;BR /&gt;
         &amp;lt;ReplyLast&amp;gt;&lt;BR /&gt;
            &amp;lt;Time&amp;gt;1407387275454&amp;lt;/Time&amp;gt;&lt;BR /&gt;
            &amp;lt;Result&amp;gt;FLR&amp;lt;/Result&amp;gt;&lt;BR /&gt;
            &amp;lt;ResultNlMsg&amp;gt;&lt;BR /&gt;
               &amp;lt;NlMsgId&amp;gt;BMC-IPS000206I&amp;lt;/NlMsgId&amp;gt;&lt;BR /&gt;
            &amp;lt;/ResultNlMsg&amp;gt;&lt;BR /&gt;
         &amp;lt;/ReplyLast&amp;gt;&lt;BR /&gt;
      &amp;lt;/Replies&amp;gt;&lt;BR /&gt;
   &amp;lt;/RequestReport&amp;gt;&lt;BR /&gt;
&lt;/CODE&gt;....&lt;/P&gt;

&lt;P&gt;With the rex expression&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`rex field=_raw ".*FLR&amp;lt;/Result&amp;gt;\s+&amp;lt;EndTime&amp;gt;(?&amp;lt;EndTime&amp;gt;.*?)&amp;lt;/EndTime&amp;gt;"`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get the EndTime value. No problem.&lt;/P&gt;

&lt;P&gt;But now I want to search to the first FLR and then to the &lt;CODE&gt;&amp;lt;NlMsgId&amp;gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`rex field=_raw ".*FLR&amp;lt;/Result&amp;gt;[WHATISMISSINGHERE??]&amp;lt;NlMsgId&amp;gt;(?&amp;lt;BMCI&amp;gt;.*?)&amp;lt;/NlMsgId&amp;gt;"`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I've to set for a regular expression that it leaves out the text between&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`FLR&amp;lt;/Result&amp;gt;`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`&amp;lt;NlMsgId&amp;gt;`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;?&lt;/P&gt;

&lt;P&gt;I can't search directly for the &lt;CODE&gt;&amp;lt;NlMsgId&amp;gt;&lt;/CODE&gt; because there are also other before the not listed text.&lt;BR /&gt;
I've tried star and a lot of other things with no success &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Also does someone has some hints where to best start so I get more familar with those regular expressions?&lt;BR /&gt;
Thanks a lot and cheers&lt;/P&gt;

&lt;P&gt;Markus&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 08:12:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178970#M51505</guid>
      <dc:creator>tbasima1</dc:creator>
      <dc:date>2014-08-12T08:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178971#M51506</link>
      <description>&lt;P&gt;Hi tbasima1,&lt;/P&gt;

&lt;P&gt;Firstly, you need an expression to match any character, including a newline. The dot does not match a newline by default, so you need alternation. Then, to remove everything up to the tag &lt;CODE&gt;&amp;lt;NlMsgId&amp;gt;&lt;/CODE&gt;, you could use a zero-width look-ahead assertion, which checks for the text following your expression.&lt;/P&gt;

&lt;P&gt;So try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; rex field=_raw ".*FLR&amp;lt;/Result&amp;gt;(?:\n|.)*(?=&amp;lt;NlMsgId&amp;gt;)&amp;lt;NlMsgId&amp;gt;(?&amp;lt;BMCI&amp;gt;.*?)&amp;lt;/NlMsgId&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;The expression &lt;CODE&gt;(?:\n|.)*&lt;/CODE&gt; matches any sequence of characters, including a newline&lt;/LI&gt;
&lt;LI&gt;The expression &lt;CODE&gt;(?=&amp;lt;NlMsgId&amp;gt;)&lt;/CODE&gt; checks that the previous expression is followed by &lt;CODE&gt;&amp;lt;NlMsgId&amp;gt;&lt;/CODE&gt;, without "eating up" the match, so it is left for the next expression to pick up&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;HTH!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 09:03:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178971#M51506</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2014-08-12T09:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178972#M51507</link>
      <description>&lt;P&gt;It struck me that a look-behind assertion might also work, but it seems they have to be of fixed width. Not sure. In any case, it would make for a messier regex.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 09:05:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178972#M51507</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2014-08-12T09:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178973#M51508</link>
      <description>&lt;P&gt;Hi echalex,&lt;/P&gt;

&lt;P&gt;thanks a lot for your support.&lt;/P&gt;

&lt;P&gt;I've tried several things but unfortunately it did not work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;
This is my command string &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=patrol sourcetype=pserverlog FLR CmdbId "&amp;lt;SmmPublishRollback&amp;gt;" | rex field=_raw ".*FLR&amp;lt;/Result&amp;gt;(?:\n|.)*(?=&amp;lt;NlMsgId&amp;gt;)&amp;lt;NlMsgId&amp;gt;(?&amp;lt;BMCI&amp;gt;.*?)&amp;lt;/NlMsgId&amp;gt;" | table _time BMCI
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Only the time column will be shown.&lt;/P&gt;

&lt;P&gt;Any idea?&lt;BR /&gt;
Thanks and cheers&lt;/P&gt;

&lt;P&gt;Markus&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 11:05:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178973#M51508</guid>
      <dc:creator>tbasima1</dc:creator>
      <dc:date>2014-08-12T11:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178974#M51509</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Do you have a different set of data now? I see your base search does not match the previous data.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 12:39:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178974#M51509</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2014-08-12T12:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178975#M51510</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
no, I've appended only the search part in front, place your rex line and appended teh tabel formatting. What do you mean with does not match the previous data?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 12:48:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178975#M51510</guid>
      <dc:creator>tbasima1</dc:creator>
      <dc:date>2014-08-12T12:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178976#M51511</link>
      <description>&lt;P&gt;I mean that the data you've pasted into the question will not be matched by the search, as it does not contain &lt;CODE&gt;&amp;lt;SmmPublishRollback&amp;gt;&lt;/CODE&gt;. Maybe you didn't past all the data into the question?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 15:47:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178976#M51511</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2014-08-12T15:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178977#M51512</link>
      <description>&lt;P&gt;sorry for the confusion. yes, there is much more data in the log. That was the reason that I've palced some ..... there. Tehb event that will be found could have 244 lines and the part that I've listed is included.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 05:42:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178977#M51512</guid>
      <dc:creator>tbasima1</dc:creator>
      <dc:date>2014-08-13T05:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178978#M51513</link>
      <description>&lt;P&gt;Ok, I see. Without seeing all your data, I can't see a reason why it works for me and not for you. Perhaps you could benefit from using xpath rather than rex?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 08:24:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178978#M51513</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2014-08-13T08:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178979#M51514</link>
      <description>&lt;P&gt;Perhaps using xpath would help you? Quick testing with the following command yields results for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search |xpath outfield=NlMsgId "*/Replies/ReplyLast[Result="FLR"]/ResultNlMsg/NlMsgId"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note, according to the &lt;A href="https://docs.splunk.com/Documentation/Splunk/6.1.2/SearchReference/Xpath"&gt;documentation for xpath&lt;/A&gt;, you should need to escape the quotes surrounding &lt;CODE&gt;FLR&lt;/CODE&gt;. However, escaping the quotes does not work for me, but the search included does.&lt;/P&gt;

&lt;P&gt;Mind you, if your data is complete and well formed, you might benefit from using the complete path, rather than a path with an asterisk, as I have done.&lt;/P&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 08:28:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178979#M51514</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2014-08-13T08:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178980#M51515</link>
      <description>&lt;P&gt;thanks for help and sorry for being a pain &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
The xpath was not working so I think that somewhere is a mistake.&lt;BR /&gt;
I found also an article that the first line with version&lt;/P&gt;

&lt;P&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/P&gt;

&lt;P&gt;could make a problem. So I've added the first few lines of the search result on the top (I've edited starting question)&lt;/P&gt;

&lt;P&gt;index=patrol sourcetype=pserverlog FLR CmdbId "&lt;SMMPUBLISHROLLBACK&gt;" | xpath outfield=NlMsgId "*/Replies/ReplyLast[Result="FLR"]/ResultNlMsg/NlMsgId" | table _time NlMsgId&lt;/SMMPUBLISHROLLBACK&gt;&lt;/P&gt;

&lt;P&gt;Got some results, but not the NlMsgId column, maybe this is a mistake?&lt;BR /&gt;
Thanks&lt;BR /&gt;
Markus&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 12:00:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178980#M51515</guid>
      <dc:creator>tbasima1</dc:creator>
      <dc:date>2014-08-13T12:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: rex over multiple lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178981#M51516</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="&amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&amp;gt; 
&amp;lt;PublishLog Version=\"5.0\"&amp;gt; &amp;lt;RequestReport&amp;gt; &amp;lt;Request&amp;gt;
&amp;lt;Id&amp;gt;Z00000hyjlq1l4Xpa3Z53MZbem7cZ&amp;lt;/Id&amp;gt; &amp;lt;StartTime&amp;gt;1407386816620&amp;lt;/StartTime&amp;gt;
&amp;lt;User&amp;gt;cli@ss001500.tauri.ch&amp;lt;/User&amp;gt; &amp;lt;Type&amp;gt;ps_publish&amp;lt;/Type&amp;gt;
&amp;lt;RequestTime&amp;gt;1407386816587&amp;lt;/RequestTime&amp;gt; &amp;lt;RequestMsg/&amp;gt; &amp;lt;Description&amp;gt;cli for user cli@ss001500.tauri.ch&amp;lt;/Description&amp;gt;
&amp;lt;ClientData/&amp;gt; &amp;lt;Result&amp;gt;FLR&amp;lt;/Result&amp;gt; &amp;lt;EndTime&amp;gt;1407387275454&amp;lt;/EndTime&amp;gt; &amp;lt;/Request&amp;gt;
&amp;lt;Replies&amp;gt; &amp;lt;ReplyFirst&amp;gt; &amp;lt;Time&amp;gt;1407386816719&amp;lt;/Time&amp;gt; &amp;lt;Result&amp;gt;ACK&amp;lt;/Result&amp;gt;
&amp;lt;RequestId&amp;gt;Z00000hyjlq1l4Xpa3Z53MZbem7cZ&amp;lt;/RequestId&amp;gt; &amp;lt;/ReplyFirst&amp;gt;
&amp;lt;ReplyLast&amp;gt; &amp;lt;Time&amp;gt;1407387275454&amp;lt;/Time&amp;gt; &amp;lt;Result&amp;gt;FLR&amp;lt;/Result&amp;gt;
&amp;lt;ResultNlMsg&amp;gt; &amp;lt;NlMsgId&amp;gt;BMC-IPS000206I&amp;lt;/NlMsgId&amp;gt; &amp;lt;/ResultNlMsg&amp;gt;
&amp;lt;/ReplyLast&amp;gt; &amp;lt;/Replies&amp;gt; &amp;lt;/RequestReport&amp;gt;"
| rex field=_raw "(?s).*FLR.*\&amp;lt;NlMsgId\&amp;gt;(?&amp;lt;BMCI&amp;gt;.*?)\&amp;lt;\/NlMsgId\&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;try option &lt;CODE&gt;(?s) (PCRE_DOTALL)&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;cf &lt;A href="https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php"&gt;PCRE Pattern Modifiers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 23:55:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-over-multiple-lines/m-p/178981#M51516</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-04T23:55:12Z</dc:date>
    </item>
  </channel>
</rss>

