<?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 an eval if field value matches a regex good otherwise bad? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344661#M102098</link>
    <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval YourFieldName=if(match(fieldToMatch,"^(\d{5})$") AND NOT match(fieldToMatch,"^0\d{4}"),"good", "bad")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 15 Apr 2018 03:19:54 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-04-15T03:19:54Z</dc:date>
    <item>
      <title>How to write an eval if field value matches a regex good otherwise bad?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344660#M102097</link>
      <description>&lt;P&gt;Need a little help writing an eval that uses a regex to check if the field value is a number 5 digits long and the 1st digit is not 0.&lt;/P&gt;

&lt;P&gt;some pseudo code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval &amp;lt;field&amp;gt;  = if (regex =match, good, bad)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 15 Apr 2018 02:17:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344660#M102097</guid>
      <dc:creator>Log_wrangler</dc:creator>
      <dc:date>2018-04-15T02:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to write an eval if field value matches a regex good otherwise bad?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344661#M102098</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval YourFieldName=if(match(fieldToMatch,"^(\d{5})$") AND NOT match(fieldToMatch,"^0\d{4}"),"good", "bad")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Apr 2018 03:19:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344661#M102098</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-15T03:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to write an eval if field value matches a regex good otherwise bad?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344662#M102099</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/75933"&gt;@Log_wrangler&lt;/a&gt;, the regular Expression that you need is &lt;CODE&gt;^((?!0)(\d{1,5}))$&lt;/CODE&gt;. &lt;STRONG&gt;It will not match if the Account_ID start with 0 or if the length of Account_ID is &amp;gt; 5 or any non-numeric character is present in the Account_ID.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Following is a run anywhere example with some sample data to test:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Account_ID="87347,123,1,0,848/'A$,993884,000,0123,949A4,48A4" 
| makemv Account_ID delim="," 
| mvexpand Account_ID 
| eval validation_result= if(match(Account_ID,"^((?!0)(\d{1,5}))$"),"good","bad")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to understand how this Regular Expression works try out on &lt;CODE&gt;regex101&lt;/CODE&gt;(link attached):  &lt;A href="https://regex101.com/r/f0QOAB/1" target="_blank"&gt;https://regex101.com/r/f0QOAB/1&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:06:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344662#M102099</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T19:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to write an eval if field value matches a regex good otherwise bad?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344663#M102100</link>
      <description>&lt;P&gt;thank you for the reply, I like the way you wrote this in parts, fyi I changed this &lt;CODE&gt;"^(\d{1,5})$")&lt;/CODE&gt;  and this &lt;CODE&gt;"^0\d{1,4}"&lt;/CODE&gt; but I still need to eval any account_id starting with 0 as bad including if its only one digit.&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 22:02:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-an-eval-if-field-value-matches-a-regex-good/m-p/344663#M102100</guid>
      <dc:creator>Log_wrangler</dc:creator>
      <dc:date>2018-04-16T22:02:18Z</dc:date>
    </item>
  </channel>
</rss>

