<?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: Extract string from text based on character position in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-string-from-text-based-on-character-position/m-p/457776#M129282</link>
    <description>&lt;P&gt;@kharlow, try the following regular expression&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  "[^-]+-[^-]+-\D+(?&amp;lt;field&amp;gt;[^-]+)-"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or if the raw data/field name on which regular expression is being applied begins with the format specified in the question&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  "^[^-]+-[^-]+-\D+(?&amp;lt;field&amp;gt;[^-]+)-"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search example based on your sample data where commands from makeresults to rename generate sample raw events as per the question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="foo-1a-barr12345678-aa11;foo-2b-baar87654321-bb22;foo-2c-bbar18273645-aa12"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| rex field=_raw "[^-]+-[^-]+-\D+(?&amp;lt;field&amp;gt;[^-]+)-"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Jul 2018 06:41:55 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2018-07-26T06:41:55Z</dc:date>
    <item>
      <title>Extract string from text based on character position</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-string-from-text-based-on-character-position/m-p/457775#M129281</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I’m looking to extract a numerical value from a string, however struggling as there is nothing to use as a delimiter &lt;/P&gt;

&lt;P&gt;I tried using this however it doesn’t work &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; (\s){11}(8&amp;lt;field&amp;gt;\s)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;P&gt;foo-1a-barr12345678-aa11&lt;BR /&gt;
foo-2b-baar87654321-bb22&lt;BR /&gt;
foo-2c-bbar18273645-aa12&lt;/P&gt;

&lt;P&gt;I wish to extract the number starting from char 12 to 20:&lt;BR /&gt;
12345678&lt;BR /&gt;
87654321&lt;BR /&gt;
18273645&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 04:44:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-string-from-text-based-on-character-position/m-p/457775#M129281</guid>
      <dc:creator>kharlow</dc:creator>
      <dc:date>2018-07-26T04:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string from text based on character position</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-string-from-text-based-on-character-position/m-p/457776#M129282</link>
      <description>&lt;P&gt;@kharlow, try the following regular expression&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  "[^-]+-[^-]+-\D+(?&amp;lt;field&amp;gt;[^-]+)-"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or if the raw data/field name on which regular expression is being applied begins with the format specified in the question&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  "^[^-]+-[^-]+-\D+(?&amp;lt;field&amp;gt;[^-]+)-"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search example based on your sample data where commands from makeresults to rename generate sample raw events as per the question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="foo-1a-barr12345678-aa11;foo-2b-baar87654321-bb22;foo-2c-bbar18273645-aa12"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| rex field=_raw "[^-]+-[^-]+-\D+(?&amp;lt;field&amp;gt;[^-]+)-"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Jul 2018 06:41:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-string-from-text-based-on-character-position/m-p/457776#M129282</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-07-26T06:41:55Z</dc:date>
    </item>
  </channel>
</rss>

