<?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: How to write the regular expression to extract these fields from my sample data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278276#M83998</link>
    <description>&lt;P&gt;Hello Friend,&lt;/P&gt;

&lt;P&gt;If you want to extract the fields for both the events with one regex, then try using the below regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.*msg\=(?.*)?suid\=(?\d+)?\ssname\=(?.*)?suser\=(?.*)?\sspid\=(?\d+)\sdst\=(?\d+\.\d+\.\d+\.\d+)\s(?:dhost\=(?\w+)\sdport\=(?\d+)|(?:dpt\=(?\d+)\sduser\=(?\w+)))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that works for you.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2016 14:19:58 GMT</pubDate>
    <dc:creator>rahulrawlani</dc:creator>
    <dc:date>2016-12-14T14:19:58Z</dc:date>
    <item>
      <title>How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278269#M83991</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to create a regex to extract the fields to the follow logs:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Example 1&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;msg=O equipamento marte (192.168.0.1) recuperou a conectividade SSH suid=7 sname=Script Assíncrono: 10 suser= spid=17025 dst=192.168.0.2 dhost=marte dport=22
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Example 2&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;msg=Sessao iniciada para marte (192.168.0.1) - Usuario Privilegiado TPL - root pelo usuario Usuario Teste (usuario.teste) suid=297 sname=Usuario Teste suser=usuario.teste spid=14410 dst=192.168.0.1 dpt=22 duser=root
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to extract the fields like that:&lt;/P&gt;

&lt;P&gt;Example 1&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;msg=O equipamento marte (192.168.0.1) recuperou a conectividade SSH
suid=7
sname=Script Assíncrono: 10
suser=
spid=17025
dst=192.168.0.2
dhost=marte
dport=22
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 2&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;msg=Sessao iniciada para marte (192.168.0.1) - Usuario Privilegiado TPL - root pelo usuario Usuario Teste (usuario.teste)
suid=297
sname=Usuario Teste
suser=usuario.teste
spid=14410
dst=192.168.0.1
dpt=22
duser=root
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm using &lt;A href="https://regex101.com/"&gt;https://regex101.com/&lt;/A&gt; to help me&lt;/P&gt;

&lt;P&gt;Any help is appreciated&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 12:37:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278269#M83991</guid>
      <dc:creator>kschmeling</dc:creator>
      <dc:date>2016-12-13T12:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278270#M83992</link>
      <description>&lt;P&gt;I am surprised this isn't happening automatically.  Under normal circustances, Splunk would find any "key=value" pairs in inputs. &lt;/P&gt;

&lt;P&gt;Have you repeated your search in Verbose mode to make sure you can see the fields it's already found?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 13:27:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278270#M83992</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2016-12-13T13:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278271#M83993</link>
      <description>&lt;P&gt;I believe the default parser uses space as a delimiter so  he'd end up with 'msg=O' and 'msg=Sessao'.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 13:47:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278271#M83993</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-12-13T13:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278272#M83994</link>
      <description>&lt;P&gt;The examples are little different, which makes finding a common regex string tricky, but I believe this will work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"msg=(?&amp;lt;msg&amp;gt;.*?) suid=(?&amp;lt;suid&amp;gt;\d+) sname=(?&amp;lt;sname&amp;gt;.*?) suser=(?&amp;lt;suser&amp;gt;.*) spid=(?&amp;lt;spid&amp;gt;\d+) dst=(?&amp;lt;dst&amp;gt;[^ ]+) (dhost=(?&amp;lt;dhost&amp;gt;.*?) dport=(?&amp;lt;dport&amp;gt;\d+))?(dpt=(?&amp;lt;dpt&amp;gt;\d+) duser=(?&amp;lt;duser&amp;gt;.*))?"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Dec 2016 13:57:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278272#M83994</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-12-13T13:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278273#M83995</link>
      <description>&lt;P&gt;Yes, Splunk give me this results:&lt;/P&gt;

&lt;P&gt;msg=O&lt;BR /&gt;
msh=Sessao&lt;BR /&gt;
sname=Script&lt;BR /&gt;
sname=Usuario&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 15:15:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278273#M83995</guid>
      <dc:creator>kschmeling</dc:creator>
      <dc:date>2016-12-13T15:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278274#M83996</link>
      <description>&lt;P&gt;Yes, I realized that would have been the case after I had another cup of coffee and the wonderfully talented richgalloway reminded me of same.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;There should be an answer below - give it a try and if it works for you, please accept it!&lt;/P&gt;

&lt;P&gt;Happy Splunking!&lt;/P&gt;

&lt;P&gt;-Rich&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 15:17:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278274#M83996</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2016-12-13T15:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278275#M83997</link>
      <description>&lt;P&gt;Perfect, it's working. The trick is this expression:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(dhost=(?&amp;lt;dhost&amp;gt;.*?) dport=(?&amp;lt;dport&amp;gt;\d+))?(dpt=(?&amp;lt;dpt&amp;gt;\d+) duser=(?&amp;lt;duser&amp;gt;.*))?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 15:37:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278275#M83997</guid>
      <dc:creator>kschmeling</dc:creator>
      <dc:date>2016-12-13T15:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regular expression to extract these fields from my sample data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278276#M83998</link>
      <description>&lt;P&gt;Hello Friend,&lt;/P&gt;

&lt;P&gt;If you want to extract the fields for both the events with one regex, then try using the below regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.*msg\=(?.*)?suid\=(?\d+)?\ssname\=(?.*)?suser\=(?.*)?\sspid\=(?\d+)\sdst\=(?\d+\.\d+\.\d+\.\d+)\s(?:dhost\=(?\w+)\sdport\=(?\d+)|(?:dpt\=(?\d+)\sduser\=(?\w+)))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that works for you.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 14:19:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regular-expression-to-extract-these-fields-from/m-p/278276#M83998</guid>
      <dc:creator>rahulrawlani</dc:creator>
      <dc:date>2016-12-14T14:19:58Z</dc:date>
    </item>
  </channel>
</rss>

