<?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 rex to remove leading zeros in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386051#M112698</link>
    <description>&lt;P&gt;You can use ltrim function&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults| eval x="001727"|eval x= ltrim(tostring(x),"0")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 04 Jan 2019 17:12:41 GMT</pubDate>
    <dc:creator>Vijeta</dc:creator>
    <dc:date>2019-01-04T17:12:41Z</dc:date>
    <item>
      <title>Use rex to remove leading zeros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386049#M112696</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Regex:&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;Printed\s\s\s\s.(.+)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Test String:&lt;/STRONG&gt;&lt;BR /&gt;
Printed     : 001727&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;BR /&gt;
1. 001727 &lt;/P&gt;

&lt;P&gt;I want the output to display without the leading zeros. so as it appears: 1727&lt;/P&gt;

&lt;P&gt;Can anybody help?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 17:05:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386049#M112696</guid>
      <dc:creator>bablucho</dc:creator>
      <dc:date>2019-01-04T17:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Use rex to remove leading zeros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386050#M112697</link>
      <description>&lt;P&gt;The rex string I'd use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Printed[\s:]+[0]*(?&amp;lt;your_field&amp;gt;[0-9]+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jan 2019 17:12:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386050#M112697</guid>
      <dc:creator>wenthold</dc:creator>
      <dc:date>2019-01-04T17:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use rex to remove leading zeros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386051#M112698</link>
      <description>&lt;P&gt;You can use ltrim function&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults| eval x="001727"|eval x= ltrim(tostring(x),"0")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jan 2019 17:12:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386051#M112698</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-01-04T17:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Use rex to remove leading zeros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386052#M112699</link>
      <description>&lt;P&gt;Probably something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Printed\D+0*(\d+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;should work. &lt;CODE&gt;\D+&lt;/CODE&gt; is all non-digits, followed by zero or more &lt;CODE&gt;0&lt;/CODE&gt;'s, then it puts the other digits is the capture group.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 17:13:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386052#M112699</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2019-01-04T17:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Use rex to remove leading zeros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386053#M112700</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;if you convert the string to integer, it will get rid of the leading zeros

| makeresults
| eval String="00147"
| eval StringInt = tonumber(String)
| table String StringInt

Else if you want to keep it as a string, you can try using this regex
| makeresults
| eval String="00147"
|rex field=String "(?&amp;lt;Output&amp;gt;[^0+]\S+)" 
| table String Output
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jan 2019 17:23:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386053#M112700</guid>
      <dc:creator>saurabhkharkar</dc:creator>
      <dc:date>2019-01-04T17:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Use rex to remove leading zeros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386054#M112701</link>
      <description>&lt;P&gt;If one of these answers has worked for you, please accept the answer, so that future viewers of this question can know that it has been answered for you, and which one worked for you.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 02:26:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386054#M112701</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2019-01-08T02:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use rex to remove leading zeros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386055#M112702</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test=0000123456000001200 
| rex field="test" mode=sed "s/(^0*)//1"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Result: 123456000001200&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 05:06:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-rex-to-remove-leading-zeros/m-p/386055#M112702</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-01-08T05:06:14Z</dc:date>
    </item>
  </channel>
</rss>

