<?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: Regex Help in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332941#M99022</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You can try below regex to exclude preceding zeros:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?!(0))(?&amp;lt;DEP&amp;gt;\d{3})(?&amp;lt;MOV&amp;gt;\d{3})(?&amp;lt;PLU&amp;gt;\d{7})(?&amp;lt;PV&amp;gt;\d{9})(?&amp;lt;EPLU&amp;gt;\d{2})(?&amp;lt;CPLU&amp;gt;\d{2})(?&amp;lt;SEQUEN&amp;gt;\d+)\s*?(?&amp;lt;FEC&amp;gt;\d{16})(?&amp;lt;ORI&amp;gt;.{1})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also another way is you can apply one more regex on field &lt;CODE&gt;DEP&lt;/CODE&gt; to avoid preceding zeros after main search.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Apr 2018 06:14:19 GMT</pubDate>
    <dc:creator>p_gurav</dc:creator>
    <dc:date>2018-04-12T06:14:19Z</dc:date>
    <item>
      <title>Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332940#M99021</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;

&lt;P&gt;Can you please help me create a regular expression that allows me to exclude the leading zeros of a limited string.&lt;/P&gt;

&lt;P&gt;I have the following data structure:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;05755060010220000002000502234704       20180411135906798L
07095060010220000002300502234705       20180411135906798L
03545070022971000013950504434706       20180411135906798L
00785060060099000011150504034707       20180411135906798L
00745060070142000001550504034708       20180411135906798L
00305070079758000010000502234709       20180411135906798L
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is my regular expression:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^(?&amp;lt;DEP&amp;gt;\d{4})(?&amp;lt;MOV&amp;gt;\d{3})(?&amp;lt;PLU&amp;gt;\d{7})(?&amp;lt;PV&amp;gt;\d{9})(?&amp;lt;EPLU&amp;gt;\d{2})(?&amp;lt;CPLU&amp;gt;\d{2})(?&amp;lt;SEQUEN&amp;gt;\d+)\s*?(?&amp;lt;FEC&amp;gt;\d{16})(?&amp;lt;ORI&amp;gt;.{1})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first field has a length of 4 digits, but this can contain 1,2,3 or no zero at the beginning, I must clean these zeros they stayed like this:&lt;/P&gt;

&lt;P&gt;original = 0575&lt;BR /&gt;
acceptable= 575&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 21:55:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332940#M99021</guid>
      <dc:creator>lufermalgo</dc:creator>
      <dc:date>2018-04-11T21:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332941#M99022</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You can try below regex to exclude preceding zeros:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?!(0))(?&amp;lt;DEP&amp;gt;\d{3})(?&amp;lt;MOV&amp;gt;\d{3})(?&amp;lt;PLU&amp;gt;\d{7})(?&amp;lt;PV&amp;gt;\d{9})(?&amp;lt;EPLU&amp;gt;\d{2})(?&amp;lt;CPLU&amp;gt;\d{2})(?&amp;lt;SEQUEN&amp;gt;\d+)\s*?(?&amp;lt;FEC&amp;gt;\d{16})(?&amp;lt;ORI&amp;gt;.{1})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also another way is you can apply one more regex on field &lt;CODE&gt;DEP&lt;/CODE&gt; to avoid preceding zeros after main search.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 06:14:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332941#M99022</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-04-12T06:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332942#M99023</link>
      <description>&lt;P&gt;To keep it simple and because you don't know how many leading zeros you have, I would keep your regex as you have it, and then strip off the leading zeros in a second step.&lt;/P&gt;

&lt;P&gt;e.g.&lt;BR /&gt;
&lt;CODE&gt;| rex field=DEP "^0*(?&amp;lt;DEP&amp;gt;[1-9]+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;or&lt;BR /&gt;
&lt;CODE&gt;| eval DEP=ltrim(DEP,"0")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 07:16:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332942#M99023</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-12T07:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332943#M99024</link>
      <description>&lt;P&gt;@FrankVl &lt;BR /&gt;
thanks for your reply,&lt;/P&gt;

&lt;P&gt;My instance is splunkcloud and the support staff does not agree that these transformations are done in search time, it is for this reason that I am looking to make the excllusion of zero initials in each field that I extract.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 12:29:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332943#M99024</guid>
      <dc:creator>lufermalgo</dc:creator>
      <dc:date>2018-04-12T12:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332944#M99025</link>
      <description>&lt;P&gt;@p_gurav&lt;/P&gt;

&lt;P&gt;thanks for your reply,&lt;/P&gt;

&lt;P&gt;The expression must respect the fixed length and applied to all the fields that are extracted.&lt;/P&gt;

&lt;P&gt;Let me explain, the DEP field is of a fine length of 4 digits, this should exclude the amount of zero that appeared but increasing the length of 4 digits.&lt;/P&gt;

&lt;P&gt;Ex:&lt;/P&gt;

&lt;P&gt;0456 - 456&lt;BR /&gt;
0089 - 89&lt;BR /&gt;
0009 - 9&lt;/P&gt;

&lt;P&gt;It can not exceed the length because in that case it would be taking digits from another field.&lt;/P&gt;

&lt;P&gt;The same for the other fields PLU, MOV, PV, etc ...&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 12:33:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332944#M99025</guid>
      <dc:creator>lufermalgo</dc:creator>
      <dc:date>2018-04-12T12:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332945#M99026</link>
      <description>&lt;P&gt;Ok, I assumed you were running this in the search bar indeed.&lt;/P&gt;

&lt;P&gt;Not too familiar with how things are managed on splunkcloud, but perhaps you can explain how you are configuring this? Is this being done at indextime?&lt;/P&gt;

&lt;P&gt;If it is indeed index time using transforms, you could still add an extra transforms stanza that uses the DEP field as the SOURCE_KEY and DEST_KEY and then applies the regex similar to what I suggested.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:01:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332945#M99026</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2020-09-29T19:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332946#M99027</link>
      <description>&lt;P&gt;@FrankVl &lt;BR /&gt;
thanks for your reply,&lt;/P&gt;

&lt;P&gt;Could you please give me an example?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 14:08:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332946#M99027</guid>
      <dc:creator>lufermalgo</dc:creator>
      <dc:date>2018-04-12T14:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332947#M99028</link>
      <description>&lt;P&gt;Again: not entirely sure how this is managed in splunk cloud, but assuming you are applying the regex you shared as an index time extraction, I would add the following to props and  transforms.conf to add an extra index time extraction to strip the 0s off the DEP field:&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your sourcetype here]
TRANSFORMS-DEPstripzeros = DEP-strip-leading-zeros
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[DEP-strip-leading-zeros]
REGEX = ^0*([1-9]+)
SOURCE_KEY = DEP
DEST_KEY = DEP
FORMAT = $1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 12:30:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332947#M99028</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-13T12:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332948#M99029</link>
      <description>&lt;P&gt;Hi @FrankVl &lt;/P&gt;

&lt;P&gt;Thanks for your answer,&lt;/P&gt;

&lt;P&gt;When parting something is not going well, when restarting the service it generates me the following error message and the tado keeps conserving the initial zeros.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Undocumented key used in transforms.conf; stanza='DEP-strip-leading-zeros' setting='SOURCE_KEY' key='DEP'
Undocumented key used in transforms.conf; stanza='DEP-strip-leading-zeros' setting='DEST_KEY' key='DEP'
Please resolve these problems by correcting typos in key names, or by adding them to [accepted_keys] in transforms.conf if they are intended.

05755060010220000002000502234704       20180411135906798L
DEP=0575
FEC=20180411135906798
MOV=506
OCPLU=22
OEPLU=50
OPV=000002000
ORI=L
PLU=0010220
SECUEN=34704
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Should I consider something else?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 12:45:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332948#M99029</guid>
      <dc:creator>lufermalgo</dc:creator>
      <dc:date>2018-04-13T12:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332949#M99030</link>
      <description>&lt;P&gt;My bad, for index time extractions, you cannot refer to already extracted fields, only to a few default KEYS.&lt;/P&gt;

&lt;P&gt;What you could of course do, is keep the value incl. leading zeros at index time, but strip off the leading zero's at search time.&lt;/P&gt;

&lt;P&gt;So either do that as part of your searches as suggested above, or automatically in props.conf with an eval command (calculated field):&lt;BR /&gt;
&lt;CODE&gt;EVAL-DEP=ltrim(DEP,"0")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 13:02:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332949#M99030</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-13T13:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332950#M99031</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;

&lt;P&gt;I wanted to do it in indexing time to avoid loading when I search, since the data volume is high.&lt;/P&gt;

&lt;P&gt;Thanks for supporting me, I'm going to do it in search time to see how it goes.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 13:08:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Help/m-p/332950#M99031</guid>
      <dc:creator>lufermalgo</dc:creator>
      <dc:date>2018-04-13T13:08:10Z</dc:date>
    </item>
  </channel>
</rss>

