<?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 create a regex to extract fields between two hyphens? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428062#M122507</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval str="F-FIDR-67" 
| eval result = mvindex(split(str,"-"),1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Jun 2019 15:23:44 GMT</pubDate>
    <dc:creator>vnravikumar</dc:creator>
    <dc:date>2019-06-18T15:23:44Z</dc:date>
    <item>
      <title>How to create a regex to extract fields between two hyphens?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428058#M122503</link>
      <description>&lt;P&gt;Hi,help me in writing regex to extract field between two hyhpens.&lt;/P&gt;

&lt;P&gt;Eg: S-STRA-32&lt;BR /&gt;
F-FIDR-67&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:49:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428058#M122503</guid>
      <dc:creator>Deepz2612</dc:creator>
      <dc:date>2019-06-18T13:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to extract fields between two hyphens?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428059#M122504</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Please try below regex, it will extract data in new field called &lt;CODE&gt;extracted_field&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| rex field=&amp;lt;yourfield&amp;gt; "^[^\-]+\-(?&amp;lt;extracted_field&amp;gt;[^\-]+)\-"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jun 2019 14:17:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428059#M122504</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-18T14:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to extract fields between two hyphens?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428060#M122505</link>
      <description>&lt;P&gt;Hello @Deepz2612,&lt;/P&gt;

&lt;P&gt;Please try regex:  &lt;CODE&gt;-(?&amp;lt;your_field&amp;gt;.*)-&lt;/CODE&gt;. You will get value between two hyphen in "&lt;STRONG&gt;your_field&lt;/STRONG&gt;" field.&lt;/P&gt;

&lt;P&gt;This will work but if you have further information about elements on both side of hyphen you can make regex faster. For example I'm assuming we have only one characters on left side of hyphen and some digits on right side of hyphen we can use regex:  &lt;CODE&gt;[a-zA-Z]-(?&amp;lt;your_field&amp;gt;.*)-\d+&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Hope this helps!!!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 14:17:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428060#M122505</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-18T14:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to extract fields between two hyphens?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428061#M122506</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;   | rex field=&amp;lt;yourfield&amp;gt; "\-(?P&amp;lt;field_name&amp;gt;\w+)\-"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jun 2019 14:34:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428061#M122506</guid>
      <dc:creator>pranay_adla</dc:creator>
      <dc:date>2019-06-18T14:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to extract fields between two hyphens?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428062#M122507</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval str="F-FIDR-67" 
| eval result = mvindex(split(str,"-"),1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:23:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428062#M122507</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-06-18T15:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to extract fields between two hyphens?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428063#M122508</link>
      <description>&lt;P&gt;Add this to your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex max_match=0 "(?&amp;lt;=-)(?&amp;lt;betweenHyphens&amp;gt;[^-]+)(?=-)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This captures multiples, even sequentials like when you do this, which the others do not:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval _raw="foo-bar-bat-boo"
| rex max_match=0 "(?&amp;lt;=-)(?&amp;lt;betweenHyphens&amp;gt;[^-]+)(?=-)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jun 2019 17:13:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-extract-fields-between-two-hyphens/m-p/428063#M122508</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-06-18T17:13:52Z</dc:date>
    </item>
  </channel>
</rss>

