<?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 How to extract the value before a specific character using regex or rex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365743#M107854</link>
    <description>&lt;P&gt;I would like to extract the string before the first period in the field using regex or rex&lt;/P&gt;

&lt;P&gt;example: extract ir7utbws001     before the period .Feb-12-2016.043./dev/sdi and likewise in all these&lt;/P&gt;

&lt;P&gt;ir7utbws001.Feb-12-2016.043./dev/sdi&lt;BR /&gt;&lt;BR /&gt;
ir7mojavs12.Feb-12-2016.043./dev/sda1&lt;BR /&gt;&lt;BR /&gt;
Gcase-field-ogs-batch-004-staging.dec-12-2016.043&lt;BR /&gt;&lt;BR /&gt;
sb7sdamb002.Feb-12-2016.043./dev/sdn&lt;BR /&gt;&lt;BR /&gt;
ebase73-ist-bat-002.Feb-12-2016.043./dev/sda1&lt;BR /&gt;&lt;BR /&gt;
ik2itpcp002.Feb-12-2016.043./dev/sda1&lt;BR /&gt;&lt;BR /&gt;
ebase-field-ods-batch-003.Feb-12-2016.043./dev/sdi&lt;BR /&gt;&lt;BR /&gt;
Leo-batch-001.Feb-12-2016.043./dev/sda1                 &lt;/P&gt;</description>
    <pubDate>Mon, 12 Feb 2018 22:34:25 GMT</pubDate>
    <dc:creator>leagawa</dc:creator>
    <dc:date>2018-02-12T22:34:25Z</dc:date>
    <item>
      <title>How to extract the value before a specific character using regex or rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365743#M107854</link>
      <description>&lt;P&gt;I would like to extract the string before the first period in the field using regex or rex&lt;/P&gt;

&lt;P&gt;example: extract ir7utbws001     before the period .Feb-12-2016.043./dev/sdi and likewise in all these&lt;/P&gt;

&lt;P&gt;ir7utbws001.Feb-12-2016.043./dev/sdi&lt;BR /&gt;&lt;BR /&gt;
ir7mojavs12.Feb-12-2016.043./dev/sda1&lt;BR /&gt;&lt;BR /&gt;
Gcase-field-ogs-batch-004-staging.dec-12-2016.043&lt;BR /&gt;&lt;BR /&gt;
sb7sdamb002.Feb-12-2016.043./dev/sdn&lt;BR /&gt;&lt;BR /&gt;
ebase73-ist-bat-002.Feb-12-2016.043./dev/sda1&lt;BR /&gt;&lt;BR /&gt;
ik2itpcp002.Feb-12-2016.043./dev/sda1&lt;BR /&gt;&lt;BR /&gt;
ebase-field-ods-batch-003.Feb-12-2016.043./dev/sdi&lt;BR /&gt;&lt;BR /&gt;
Leo-batch-001.Feb-12-2016.043./dev/sda1                 &lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 22:34:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365743#M107854</guid>
      <dc:creator>leagawa</dc:creator>
      <dc:date>2018-02-12T22:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the value before a specific character using regex or rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365744#M107855</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| rex "^(?&amp;lt;name_of_new_field&amp;gt;.+?)\."
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Explanation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Anchor to the beginning of the line.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;name_of_new_field&amp;gt; some regular expression )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is just  saying that whatever is in the parenthesis is a named capture group. Whatever you put between the &lt;CODE&gt;&amp;lt;&lt;/CODE&gt; and &lt;CODE&gt;&amp;gt;&lt;/CODE&gt; is the name of the new field. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.+?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Grab anything &lt;CODE&gt;.&lt;/CODE&gt; one or more times &lt;CODE&gt;+&lt;/CODE&gt; until &lt;CODE&gt;?&lt;/CODE&gt; ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We find a literal dot &lt;CODE&gt;\.&lt;/CODE&gt; - the backslash is to escape its normal meaning as a wildcard character.&lt;/P&gt;

&lt;P&gt;Try checking out this link to validate it.&lt;BR /&gt;
&lt;A href="https://regex101.com/r/JvZ4fS/1"&gt;https://regex101.com/r/JvZ4fS/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Try checking out &lt;A href="https://regexone.com/"&gt;https://regexone.com/&lt;/A&gt; if you want to learn more about regular expressions.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 00:07:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365744#M107855</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2018-02-13T00:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the value before a specific character using regex or rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365745#M107856</link>
      <description>&lt;P&gt;A vastly more efficient regex (roughly 5 time more efficient) is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "^(?&amp;lt;name_of_new_field&amp;gt;[^.]*)\."
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The reason for the increase in efficiency is making the capture group look for something that is not a period and be greedy ( &lt;CODE&gt;[^.]*&lt;/CODE&gt; ), not any character and be lazy ( &lt;CODE&gt;.+?&lt;/CODE&gt; ). &lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 00:21:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365745#M107856</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2018-02-13T00:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the value before a specific character using regex or rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365746#M107857</link>
      <description>&lt;P&gt;hey try this run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="ir7utbws001.Feb-12-2016.043./dev/sdi ir7mojavs12.Feb-12-2016.043./dev/sda1 Gcase-field-ogs-batch-004-staging.dec-12-2016.043 sb7sdamb002.Feb-12-2016.043./dev/sdn" 
| makemv raw 
| mvexpand raw 
| rex field=raw "^(?P&amp;lt;field_name&amp;gt;[^\.]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your environment you should write &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex  "^(?P&amp;lt;field_name&amp;gt;[^\.]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 06:12:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/365746#M107857</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-02-13T06:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the value before a specific character using regex or rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/599584#M208696</link>
      <description>&lt;P&gt;Just curious.&lt;BR /&gt;How would this work if in the same example we have&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ir7utbws001&lt;/P&gt;&lt;P&gt;as an entry&lt;/P&gt;&lt;P&gt;as there is no 'period' your code would extract this as null. I wanted to extract the whole field if there is no period&lt;/P&gt;&lt;P&gt;So basically what is alternative of&lt;/P&gt;&lt;P&gt;| eval temp=split(URL,".")&lt;BR /&gt;| eval Final=mvindex(temp,0)&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 13:39:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-value-before-a-specific-character-using-regex/m-p/599584#M208696</guid>
      <dc:creator>siksaw33</dc:creator>
      <dc:date>2022-05-27T13:39:28Z</dc:date>
    </item>
  </channel>
</rss>

