<?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 from source in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70360#M17596</link>
    <description>&lt;P&gt;i am trying to extract the word "NUM" from source=c:/documents/app/test1/test12/controlNUM34/12.log.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Sep 2013 01:43:11 GMT</pubDate>
    <dc:creator>thinksplunk</dc:creator>
    <dc:date>2013-09-24T01:43:11Z</dc:date>
    <item>
      <title>Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70357#M17593</link>
      <description>&lt;P&gt;if i need to extract "num" from source=c:/documents/app/test1/test12/controlnum34/12.log and tag as field, how to go abt doing it? thks&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 12:04:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70357#M17593</guid>
      <dc:creator>thinksplunk</dc:creator>
      <dc:date>2013-09-23T12:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70358#M17594</link>
      <description>&lt;P&gt;Hi Thinksplunk - can you give a few more samples? Are you trying to extract:&lt;/P&gt;

&lt;P&gt;source=c:/documents/app/test1/test12/control*&lt;EM&gt;num&lt;/EM&gt;*34/12.log&lt;/P&gt;

&lt;P&gt;or:&lt;/P&gt;

&lt;P&gt;source=c:/documents/app/test1/test12/controlnum*&lt;EM&gt;34&lt;/EM&gt;*/12.log?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:49:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70358#M17594</guid>
      <dc:creator>rturk</dc:creator>
      <dc:date>2020-09-28T14:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70359#M17595</link>
      <description>&lt;P&gt;You can do field extractions dynamically in the search with the &lt;CODE&gt;rex&lt;/CODE&gt; command;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_base_search | rex field=source "your regex with a capture group here"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to capture "34" an put it in a field called &lt;CODE&gt;num&lt;/CODE&gt;;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_base_search | rex field=source "(?&amp;lt;num&amp;gt;\d+)/[^/]+$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which is to be read as, capture one or more digits (and call them &lt;CODE&gt;num&lt;/CODE&gt;) that are followed by one slash, which is followed by one or more non-slash characters, followed by the end-of-line.&lt;/P&gt;

&lt;P&gt;Once you're happy with your regex field extraction, you should probably make it 'permanent' by adding the extraction rule to props.conf as an EXTRACT.&lt;/P&gt;

&lt;P&gt;See more here:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.4/Knowledge/Addfieldsatsearchtime"&gt;http://docs.splunk.com/Documentation/Splunk/5.0.4/Knowledge/Addfieldsatsearchtime&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.4/Knowledge/Createandmaintainsearch-timefieldextractionsthroughconfigurationfiles"&gt;http://docs.splunk.com/Documentation/Splunk/5.0.4/Knowledge/Createandmaintainsearch-timefieldextractionsthroughconfigurationfiles&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 14:38:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70359#M17595</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-23T14:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70360#M17596</link>
      <description>&lt;P&gt;i am trying to extract the word "NUM" from source=c:/documents/app/test1/test12/controlNUM34/12.log.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2013 01:43:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70360#M17596</guid>
      <dc:creator>thinksplunk</dc:creator>
      <dc:date>2013-09-24T01:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70361#M17597</link>
      <description>&lt;P&gt;How about:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Search | rex field=_raw .*capture(?&amp;lt;NUM&amp;gt;num)34/12.log.*$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Sep 2013 02:18:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70361#M17597</guid>
      <dc:creator>lukejadamec</dc:creator>
      <dc:date>2013-09-24T02:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70362#M17598</link>
      <description>&lt;P&gt;faster  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;... | eval num="num" | ...&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2013 19:45:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70362#M17598</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-24T19:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70363#M17599</link>
      <description>&lt;P&gt;I'm guessing that you want to extract XXX in the following scenario, where XXX is a string that follows 'control' and 'yy' is one or more digits. Not the literal string 'num', right?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;/controlXXXyy/zzz.log&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In that case;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;rex field=source "/control(?&amp;lt;XXX&amp;gt;[a-zA-Z]+)\d+/[^/]+$"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2013 19:52:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70363#M17599</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-24T19:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70364#M17600</link>
      <description>&lt;P&gt;&lt;CODE&gt;... | rex field=source "^/[^/]+/(?&amp;lt;animal&amp;gt;[a-zA-Z]+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Which means, from the start of the string in the field called &lt;CODE&gt;source&lt;/CODE&gt;, find a single slash, followed by one or more non-slash characters, followed by a single slash - then take all (but at least one) uppercase or lowercase letters you find, and put them in the field 'animal'. &lt;/P&gt;

&lt;P&gt;As you'll find, the field will only contain 'dog' in this scenario, as the dash between 'dog' and 'focus' is not a letter.&lt;/P&gt;

&lt;P&gt;You can probably benefit from reading up on regular expressions if you want to make more dynamic extractions. &lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2013 19:52:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70364#M17600</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-26T19:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70365#M17601</link>
      <description>&lt;P&gt;If regex was that easy, then I would have answered.:)&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2013 00:57:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70365#M17601</guid>
      <dc:creator>lukejadamec</dc:creator>
      <dc:date>2013-09-27T00:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70366#M17602</link>
      <description>&lt;P&gt;This really isn't an answer, but more of a comment that applies to all of these great solutions.  An approach using the &lt;CODE&gt;rex&lt;/CODE&gt; command will work great.  But, if you try to put this into a configuration file as a permanent field extraction ( &lt;CODE&gt;props.conf&lt;/CODE&gt; or &lt;CODE&gt;transforms.conf&lt;/CODE&gt; ) and want to use it in a base search, you will probably not get the result you're looking for.  The reason for this is when you do a search for something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysourcetype myfieldfromsource=123
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;splunk will look for the token "123" within the raw text of the event - it will not look in the &lt;CODE&gt;source&lt;/CODE&gt; field.&lt;/P&gt;

&lt;P&gt;If you want to extract a regular expression from &lt;CODE&gt;source&lt;/CODE&gt; and have it searchable as a field name in a base search then you will need to make it an indexed field.  Indexed fields are not recommended for a variety of very good reasons, not the least of which is they are must be defined in advance and are very inflexible.  But if this is what you need to solve your problem, it is available to you.  &lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2013 03:46:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70366#M17602</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2013-09-27T03:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70367#M17603</link>
      <description>&lt;P&gt;If i need to extract two fields from below string&lt;BR /&gt;
"source=/app/cups-drink/test/iron13-machine5a-43machine.log"&lt;BR /&gt;
The first field name is "item" and value is "cups"&lt;BR /&gt;
The second field name is "system" and value is "43machine"&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2013 02:27:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70367#M17603</guid>
      <dc:creator>thinksplunk</dc:creator>
      <dc:date>2013-10-01T02:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70368#M17604</link>
      <description>&lt;P&gt;Given your question here, and in other posts I suggest that you read up on regex in general.&lt;/P&gt;

&lt;P&gt;e.g. &lt;A href="http://www.regular-expressions.info"&gt;http://www.regular-expressions.info&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://gskinner.com/RegExr/"&gt;http://gskinner.com/RegExr/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In this case (one of) the answer(s) is;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;rex field=source "/app/(?&amp;lt;item&amp;gt;[a-z]+)([^/]+/){2}.+(?&amp;lt;system&amp;gt;[^-]+)\.log$&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Which is; find '/app/', then take any a-z characters and call them &lt;CODE&gt;item&lt;/CODE&gt;. Then jump over any non-slash characters followed by a slash, twice. Then skip through any characters, until you find a set of non-dash characters followed by &lt;CODE&gt;.log&lt;/CODE&gt; at the end of the string. Call these non-dash characters &lt;CODE&gt;system&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2013 07:05:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-source/m-p/70368#M17604</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-10-01T07:05:47Z</dc:date>
    </item>
  </channel>
</rss>

