<?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: Getting first match field in a event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305888#M164746</link>
    <description>&lt;P&gt;Based on the sample data provided please try the following &lt;CODE&gt;rex&lt;/CODE&gt; command with max_match=1 (which is by default):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="~getenrolled, ~enroll, ~submit, ~somethingelse, ~somethingnew"
|  rex  "~(?&amp;lt;FirstAPIName&amp;gt;[^,]+)," max_match=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, you can also use &lt;CODE&gt;caret sign ( ^ )&lt;/CODE&gt; if you want to extract required API Name only from beginning of raw data (depends on the data, if this does not work please provide sample raw data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="~getenrolled, ~enroll, ~submit, ~somethingelse, ~somethingnew"
|  rex  "^~(?&amp;lt;FirstAPIName&amp;gt;[^,]+),"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: First two pipes with &lt;CODE&gt;makeresults&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt; are used to generate mock data for testing regular expression.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Nov 2017 13:33:43 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-28T13:33:43Z</dc:date>
    <item>
      <title>Getting first match field in a event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305887#M164745</link>
      <description>&lt;P&gt;In a service log different API being invoked each API start with ~( like ~getenrolled, ~enroll, ~submit) so is there any way to extract first API being called by rex &lt;/P&gt;

&lt;P&gt;i tried (~\w+){1} but it matching with all called API .&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 12:03:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305887#M164745</guid>
      <dc:creator>apand84</dc:creator>
      <dc:date>2017-11-28T12:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting first match field in a event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305888#M164746</link>
      <description>&lt;P&gt;Based on the sample data provided please try the following &lt;CODE&gt;rex&lt;/CODE&gt; command with max_match=1 (which is by default):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="~getenrolled, ~enroll, ~submit, ~somethingelse, ~somethingnew"
|  rex  "~(?&amp;lt;FirstAPIName&amp;gt;[^,]+)," max_match=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, you can also use &lt;CODE&gt;caret sign ( ^ )&lt;/CODE&gt; if you want to extract required API Name only from beginning of raw data (depends on the data, if this does not work please provide sample raw data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="~getenrolled, ~enroll, ~submit, ~somethingelse, ~somethingnew"
|  rex  "^~(?&amp;lt;FirstAPIName&amp;gt;[^,]+),"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: First two pipes with &lt;CODE&gt;makeresults&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt; are used to generate mock data for testing regular expression.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 13:33:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305888#M164746</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-28T13:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Getting first match field in a event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305889#M164747</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "~(?&amp;lt;FirstAPIName&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2017 14:17:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305889#M164747</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-11-28T14:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Getting first match field in a event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305890#M164748</link>
      <description>&lt;P&gt;Unfortunately it will match all called api (started with ~+API name )&lt;BR /&gt;
I wanted to extract first matched api  which is the main api call subsequent are sub api in service log .&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 17:07:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305890#M164748</guid>
      <dc:creator>apand84</dc:creator>
      <dc:date>2017-11-28T17:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Getting first match field in a event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305891#M164749</link>
      <description>&lt;P&gt;Then this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | rex max_match=1 "~(?&amp;lt;FirstAPIName&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2017 18:40:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-first-match-field-in-a-event/m-p/305891#M164749</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-11-28T18:40:10Z</dc:date>
    </item>
  </channel>
</rss>

