<?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: use if else to run different rex in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/use-if-else-to-run-different-rex/m-p/155432#M43746</link>
    <description>&lt;P&gt;You really can't do this, but there's a possible workaround.  Run both regexes, and use an eval to merge to a final field..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "(?&amp;lt;job_is_test&amp;gt;REGEX1)" | rex "(?&amp;lt;job_is_not_test&amp;gt;)REGEX2"
| eval finalfield = if(JOB_NAME=="TEST",job_is_test,job_is_not_test)
| fields -job_is_test,job_is_not_test
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 May 2014 14:52:57 GMT</pubDate>
    <dc:creator>dwaddle</dc:creator>
    <dc:date>2014-05-07T14:52:57Z</dc:date>
    <item>
      <title>use if else to run different rex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-if-else-to-run-different-rex/m-p/155431#M43745</link>
      <description>&lt;P&gt;There is a field JOB_NAME. i want to extract this field contents using an IF statement.&lt;/P&gt;

&lt;P&gt;If JOB_NAME=TEST then some regex  ELSE some other regex.&lt;/P&gt;

&lt;P&gt;Please tell me how to do this as eval if doesnt allow me to use regex in results section&lt;/P&gt;</description>
      <pubDate>Wed, 07 May 2014 14:26:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-if-else-to-run-different-rex/m-p/155431#M43745</guid>
      <dc:creator>iamniks</dc:creator>
      <dc:date>2014-05-07T14:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: use if else to run different rex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-if-else-to-run-different-rex/m-p/155432#M43746</link>
      <description>&lt;P&gt;You really can't do this, but there's a possible workaround.  Run both regexes, and use an eval to merge to a final field..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "(?&amp;lt;job_is_test&amp;gt;REGEX1)" | rex "(?&amp;lt;job_is_not_test&amp;gt;)REGEX2"
| eval finalfield = if(JOB_NAME=="TEST",job_is_test,job_is_not_test)
| fields -job_is_test,job_is_not_test
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 May 2014 14:52:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-if-else-to-run-different-rex/m-p/155432#M43746</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2014-05-07T14:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: use if else to run different rex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-if-else-to-run-different-rex/m-p/155433#M43747</link>
      <description>&lt;P&gt;Actually you CAN do this @dwaddle. The hate that &lt;CODE&gt;map&lt;/CODE&gt; gets from fezhats is crazy. &lt;CODE&gt;_&lt;/CODE&gt; fields are a little tricky so I would &lt;CODE&gt;eval&lt;/CODE&gt;/&lt;CODE&gt;rename&lt;/CODE&gt; them like I did here. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex | 

eval no_referrer_regex="MYREGEX1" |

eval referrer_regex="MYREGEX2" |

eval regex=if(_time &amp;lt; 1579250700,no_referrer_regex,referrer_regex) | eval raw=_raw |

map maxsearches=10000 search="| makeresults | eval mapped_raw=\"$$raw$$\" | rex field=mapped_raw \"$$regex$$\"" | table pst pst_epoch id action path num desc browser referrer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A second approach would just be to use ad-hoc searches in SimpleXML to set token values.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2020 22:26:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-if-else-to-run-different-rex/m-p/155433#M43747</guid>
      <dc:creator>nick405060</dc:creator>
      <dc:date>2020-01-17T22:26:32Z</dc:date>
    </item>
  </channel>
</rss>

