<?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 do I write a regex for different field extractions according to event value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458630#M129502</link>
    <description>&lt;P&gt;@eyirik data sample you provided, seem to me similar for each MODEL. It's just that some fields are optional.&lt;BR /&gt;
If it is so and you know what those fields mean, you can just use one universal regex and create a field extraction via UI or configure it in &lt;CODE&gt;props.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-models = ^(?&amp;lt;timestamp&amp;gt;.*?),(?&amp;lt;model&amp;gt;.*?),(?&amp;lt;fieldA&amp;gt;.*?)(?:,(?&amp;lt;fieldB&amp;gt;.*?))?(?:,(?&amp;lt;fieldC&amp;gt;.*?))?(?:,(?&amp;lt;fieldD&amp;gt;.*?))?(?:,(?&amp;lt;fieldE&amp;gt;.*?))?(?:,(?&amp;lt;fieldF&amp;gt;.*?))?(?:,(?&amp;lt;fieldG&amp;gt;.*?))?(?:,(?&amp;lt;fieldH&amp;gt;.*?))?(?:,(?&amp;lt;fieldI&amp;gt;.*?))?(?:,(?&amp;lt;fieldJ&amp;gt;.*?))?(?:,(?&amp;lt;fieldK&amp;gt;.*?))?(?:,(?&amp;lt;fieldL&amp;gt;.*?))?(?:,(?&amp;lt;extras&amp;gt;.*))?$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;extras&lt;/CODE&gt; is there only for cases when there are some additional / unknown fields and those will be stored in the &lt;CODE&gt;extras&lt;/CODE&gt; field.&lt;BR /&gt;
And basically if you need to extend the number of fields to be extracted, just copy the sequence &lt;CODE&gt;(?:,(?&amp;lt;fieldL&amp;gt;.*?))?&lt;/CODE&gt; over and over and change the name of the field.&lt;/P&gt;</description>
    <pubDate>Sun, 16 Dec 2018 18:14:33 GMT</pubDate>
    <dc:creator>petom</dc:creator>
    <dc:date>2018-12-16T18:14:33Z</dc:date>
    <item>
      <title>How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458621#M129493</link>
      <description>&lt;P&gt;I have events like the ones below. I want to make a different field extraction according to the value of field MODEL. &lt;/P&gt;

&lt;P&gt;MODEL values can be &lt;STRONG&gt;MD9EL, AVEV, PSJ&lt;/STRONG&gt; . Each MODEL has different events and ı have to write a regex for the different models. &lt;/P&gt;

&lt;P&gt;2018-11-02T06:24:16.000Z,&lt;STRONG&gt;MD9EL&lt;/STRONG&gt;,NLTALLZNL01000005,36.99140,35.18779&lt;/P&gt;

&lt;P&gt;2018-11-01T13:24:27.000Z,&lt;STRONG&gt;AVEV&lt;/STRONG&gt;,NLTNVSZPL01000001,36.98865,35.19343,0.63,2512&lt;/P&gt;

&lt;P&gt;2018-11-01T13:58:02.000Z,&lt;STRONG&gt;PSJ&lt;/STRONG&gt;,NLTPNG23L01002172,,,,644,35,0,0,102,0,61,102&lt;/P&gt;

&lt;P&gt;I think have to override the inputs according to the MODEL value. How can I process it? &lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 06:36:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458621#M129493</guid>
      <dc:creator>eyirik</dc:creator>
      <dc:date>2018-11-02T06:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458622#M129494</link>
      <description>&lt;P&gt;I see two main options:&lt;/P&gt;

&lt;P&gt;Use props and transforms to set specific sourcetypes based on the model. Then you can configure the required extractions for each of those specific sourcetypes. See: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Data/Advancedsourcetypeoverrides"&gt;https://docs.splunk.com/Documentation/Splunk/latest/Data/Advancedsourcetypeoverrides&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Use a generic sourcetype and write extractions that only match a certain model. Which would look something like this in props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-MD9EL = ^(?&amp;lt;timestamp&amp;gt;[^,]+),MD9EL,(?&amp;lt;fieldA&amp;gt;[^,]+),(?&amp;lt;fieldB&amp;gt;[^,]+)
EXTRACT-AVEV = ^(?&amp;lt;timestamp&amp;gt;[^,]+),AVEV,(?&amp;lt;fieldX&amp;gt;[^,]+),(?&amp;lt;fieldY&amp;gt;[^,]+),(?&amp;lt;fieldZ&amp;gt;[^,]+)... etc.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 10:51:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458622#M129494</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-11-02T10:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458623#M129495</link>
      <description>&lt;P&gt;Thanks. It works with EXTRACT-MD9EL. But this time , it extracts the model name and i cannot make model based search after field extraction. How can i add model name also as a field ?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 12:55:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458623#M129495</guid>
      <dc:creator>eyirik</dc:creator>
      <dc:date>2018-11-27T12:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458624#M129496</link>
      <description>&lt;P&gt;Just put a capturing group around that part of the data as well:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-MD9EL = ^(?&amp;lt;timestamp&amp;gt;[^,]+),(?&amp;lt;modelname&amp;gt;MD9EL),(?&amp;lt;fieldA&amp;gt;[^,]+),(?&amp;lt;fieldB&amp;gt;[^,]+)
 EXTRACT-AVEV = ^(?&amp;lt;timestamp&amp;gt;[^,]+),(?&amp;lt;modelname&amp;gt;AVEV),(?&amp;lt;fieldX&amp;gt;[^,]+),(?&amp;lt;fieldY&amp;gt;[^,]+),(?&amp;lt;fieldZ&amp;gt;[^,]+)... etc.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 13:55:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458624#M129496</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-11-27T13:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458625#M129497</link>
      <description>&lt;P&gt;Hi. First regex is worked but second one is not worked. &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;EXTRACT-MD9EL = ^(?[^,]+),MD9EL,(?[^,]+),(?[^,]+)&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;EXTRACT-MD9EL = ^(?[^,]+),(?MD9EL),(?[^,]+),(?[^,]+)&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;when i want to show field model name , field extraction does not work. &lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 18:10:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458625#M129497</guid>
      <dc:creator>eyirik</dc:creator>
      <dc:date>2018-12-11T18:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458626#M129498</link>
      <description>&lt;P&gt;As per @FrankVl  , you have to capture the named groups in the regex. Looks like you are not doing it. &lt;/P&gt;

&lt;P&gt;And test your regex at &lt;A href="http://www.regex101.com"&gt;www.regex101.com&lt;/A&gt; , its a great site.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 19:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458626#M129498</guid>
      <dc:creator>macadminrohit</dc:creator>
      <dc:date>2018-12-11T19:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458627#M129499</link>
      <description>&lt;P&gt;here is my sample event and my sample regex&lt;/P&gt;

&lt;P&gt;event: 20181211T14:49:30.000Z,MD9EL,NLTALLZNL01000005,36.98827&lt;/P&gt;

&lt;P&gt;regex working: EXTRACT-MD9EL = ^(?[^,]+),MD9EL,(?[^,]+),(?[^,]+)&lt;/P&gt;

&lt;P&gt;regex not working: EXTRACT-MD9EL = ^(?[^,]+),(?MD9EL),(?[^,]+),(?[^,]+)&lt;/P&gt;

&lt;P&gt;Where is my wrong ? &lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 19:30:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458627#M129499</guid>
      <dc:creator>eyirik</dc:creator>
      <dc:date>2018-12-11T19:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458628#M129500</link>
      <description>&lt;P&gt;I think i gt problem. In my event some values coming null. because of that extraction is not working. I send value 0, so regex worked. &lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 20:04:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458628#M129500</guid>
      <dc:creator>eyirik</dc:creator>
      <dc:date>2018-12-11T20:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458629#M129501</link>
      <description>&lt;P&gt;That's good to hear! If my solution worked for you, please mark it as accepted, so it is clear for others that this question was successfully answered.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 09:05:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458629#M129501</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-12-12T09:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a regex for different field extractions according to event value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458630#M129502</link>
      <description>&lt;P&gt;@eyirik data sample you provided, seem to me similar for each MODEL. It's just that some fields are optional.&lt;BR /&gt;
If it is so and you know what those fields mean, you can just use one universal regex and create a field extraction via UI or configure it in &lt;CODE&gt;props.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-models = ^(?&amp;lt;timestamp&amp;gt;.*?),(?&amp;lt;model&amp;gt;.*?),(?&amp;lt;fieldA&amp;gt;.*?)(?:,(?&amp;lt;fieldB&amp;gt;.*?))?(?:,(?&amp;lt;fieldC&amp;gt;.*?))?(?:,(?&amp;lt;fieldD&amp;gt;.*?))?(?:,(?&amp;lt;fieldE&amp;gt;.*?))?(?:,(?&amp;lt;fieldF&amp;gt;.*?))?(?:,(?&amp;lt;fieldG&amp;gt;.*?))?(?:,(?&amp;lt;fieldH&amp;gt;.*?))?(?:,(?&amp;lt;fieldI&amp;gt;.*?))?(?:,(?&amp;lt;fieldJ&amp;gt;.*?))?(?:,(?&amp;lt;fieldK&amp;gt;.*?))?(?:,(?&amp;lt;fieldL&amp;gt;.*?))?(?:,(?&amp;lt;extras&amp;gt;.*))?$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;extras&lt;/CODE&gt; is there only for cases when there are some additional / unknown fields and those will be stored in the &lt;CODE&gt;extras&lt;/CODE&gt; field.&lt;BR /&gt;
And basically if you need to extend the number of fields to be extracted, just copy the sequence &lt;CODE&gt;(?:,(?&amp;lt;fieldL&amp;gt;.*?))?&lt;/CODE&gt; over and over and change the name of the field.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Dec 2018 18:14:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-a-regex-for-different-field-extractions-according/m-p/458630#M129502</guid>
      <dc:creator>petom</dc:creator>
      <dc:date>2018-12-16T18:14:33Z</dc:date>
    </item>
  </channel>
</rss>

