<?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: Can you help me figure out what is the job of the rex field in this line? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383006#M111889</link>
    <description>&lt;P&gt;The &lt;CODE&gt;rex&lt;/CODE&gt; command is usually used to extract fields from an event using a regular expression.  This &lt;CODE&gt;rex&lt;/CODE&gt; command is garbled, however, so it's difficult to say precisely what it is doing.  Please re-post the query by surrounding it with backticks (`).&lt;/P&gt;</description>
    <pubDate>Mon, 31 Dec 2018 13:54:28 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2018-12-31T13:54:28Z</dc:date>
    <item>
      <title>Can you help me figure out what is the job of the rex field in this line?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383004#M111887</link>
      <description>&lt;P&gt;This is the search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=vha_pronto sourcetype=pronto_neopil_prd NOT [ search index=vha_pronto sourcetype=pronto_neopil_prd "SAF process started" earliest=-24h |rex field=_raw "(?ms)^[^\\[\\n]*\\[(?P\\w+\\-\\d+)" | return $SAF_pool ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Dec 2018 07:55:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383004#M111887</guid>
      <dc:creator>ramanir</dc:creator>
      <dc:date>2018-12-31T07:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me figure out what is the job of the rex field in this line?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383005#M111888</link>
      <description>&lt;P&gt;corrected query&lt;/P&gt;

&lt;P&gt;index=vha_pronto sourcetype=pronto_neopil_prd NOT [ search index=vha_pronto sourcetype=pronto_neopil_prd "SAF process started" earliest=-24h |rex field=_raw "(?ms)^[^\[\n]*\[(?P\w+\-\d+)" | return $SAF_pool ] &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:33:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383005#M111888</guid>
      <dc:creator>ramanir</dc:creator>
      <dc:date>2020-09-29T22:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me figure out what is the job of the rex field in this line?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383006#M111889</link>
      <description>&lt;P&gt;The &lt;CODE&gt;rex&lt;/CODE&gt; command is usually used to extract fields from an event using a regular expression.  This &lt;CODE&gt;rex&lt;/CODE&gt; command is garbled, however, so it's difficult to say precisely what it is doing.  Please re-post the query by surrounding it with backticks (`).&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 13:54:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383006#M111889</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-12-31T13:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me figure out what is the job of the rex field in this line?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383007#M111890</link>
      <description>&lt;P&gt;@ramanir - Be sure to mark your code with the code button (101 010) or by putting at least 4 spaces in front of it.  that will stop the interface from stripping out anything that looks like html.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 17:33:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383007#M111890</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-12-31T17:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me figure out what is the job of the rex field in this line?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383008#M111891</link>
      <description>&lt;P&gt;1) To answer the exact question you asked:  In a &lt;CODE&gt;rex&lt;/CODE&gt; command, the default field to be analyzed is &lt;CODE&gt;_raw&lt;/CODE&gt;, so technically, that &lt;CODE&gt;field=_raw&lt;/CODE&gt; clause simply makes the default explicit, and has no other effect on the function of the &lt;CODE&gt;rex&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;2) The overall search says, "look for events in this index and sourcetype that do not have an SAF process started record in the last 24 hours."  The function of the rex is to extract those SAF_pool values from all relevant events in the last 24 hours.&lt;/P&gt;

&lt;P&gt;3) Please mark your code when posting.  There are three easy methods (A) put grave accents (the one on the ~ key) before and after small snippets of text (b) Put at least four spaces on the line before each line of code, and a blank line before them.  (c) highlight the code and press the "code" button (101 010). &lt;/P&gt;

&lt;P&gt;My guess is that your rex really reads like this... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; "(?ms)^[^\[\\n]*\[(?P&amp;lt;SAF_pool&amp;gt;\\w+\-\\d+)"   
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That breaks down as "from the beginning of the line, throw away everything that is not an open brace or carriage return, until you get to an open brace.  after that, match one or more word characters, a hyphen, and one or more digits."  As such, your SAF_pool numbers are probably in the format &lt;CODE&gt;ABCD-123&lt;/CODE&gt; up to and including as weird as &lt;CODE&gt;AB1_cD-00123&lt;/CODE&gt;.  If the prefix is always going to be alpha, then change the &lt;CODE&gt;\\w+&lt;/CODE&gt; to &lt;CODE&gt;[A-Za-z]+&lt;/CODE&gt;.   &lt;/P&gt;

&lt;P&gt;4) Now here's a breakdown on your entire search code.  &lt;/P&gt;

&lt;P&gt;First, when there are subsearches, you always read the code from the innermost square braces.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=vha_pronto sourcetype=pronto_neopil_prd "SAF process started" 
earliest=-24h 
| rex field=_raw "(?ms)^[^\[\\n]*\[(?P\\w+\-\\d+)" 
| return $SAF_pool 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My guess is that the rex really reads like this... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; "(?ms)^[^\[\\n]*\[(?P&amp;lt;SAF_pool&amp;gt;\\w+\-\\d+)"   
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I am correct, then what that rex is doing is extracting the SAF_pool information from the events selected by that subsearch.  The subsearch brackets will then feed back the answer in a form that looks like this, for all pools started in the last 24 hours...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ( (  SAF_Pool="ABC-123"  ) OR ( SAF_pool="XYZ-456" ) OR ... )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to know why it turns into that format, look at the documentation for the "format" command.&lt;/P&gt;

&lt;P&gt;After returning those values, the rest of the search then looks like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=vha_pronto sourcetype=pronto_neopil_prd  NOT ( (  SAF_Pool="ABC-123"  ) OR ( SAF_pool="XYZ-456" ) OR ... )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which, as I said before, is basically asking "show me events in an SAF_pool that was started more than 24 hours ago.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:38:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383008#M111891</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-09-29T22:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me figure out what is the job of the rex field in this line?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383009#M111892</link>
      <description>&lt;P&gt;Look at the explanation in the upper-right pane here:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/OXBli1/1"&gt;https://regex101.com/r/OXBli1/1&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2019 04:46:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383009#M111892</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-01T04:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me figure out what is the job of the rex field in this line?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383010#M111893</link>
      <description>&lt;P&gt;thanks a  lot for your detailed answer @DalJeanis &lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2019 12:55:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-figure-out-what-is-the-job-of-the-rex-field-in/m-p/383010#M111893</guid>
      <dc:creator>ramanir</dc:creator>
      <dc:date>2019-01-01T12:55:00Z</dc:date>
    </item>
  </channel>
</rss>

