<?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 Regular expression in source in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137308#M37608</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have multiple sources like&lt;BR /&gt;
a1.gz&lt;BR /&gt;
a2.gz&lt;BR /&gt;
a3.gz&lt;BR /&gt;
a4.gz&lt;BR /&gt;
a5.gz&lt;BR /&gt;
…&lt;/P&gt;

&lt;P&gt;and so one. How can I have a subset these as source in search? I want to have something like&lt;BR /&gt;
source=a[1-3]* | stats …&lt;/P&gt;

&lt;P&gt;to use a1.gz, a2.gz and a3.gz as source but it does not accept [1-3] and gives error.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 11 Nov 2013 19:10:10 GMT</pubDate>
    <dc:creator>gimbil</dc:creator>
    <dc:date>2013-11-11T19:10:10Z</dc:date>
    <item>
      <title>Regular expression in source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137308#M37608</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have multiple sources like&lt;BR /&gt;
a1.gz&lt;BR /&gt;
a2.gz&lt;BR /&gt;
a3.gz&lt;BR /&gt;
a4.gz&lt;BR /&gt;
a5.gz&lt;BR /&gt;
…&lt;/P&gt;

&lt;P&gt;and so one. How can I have a subset these as source in search? I want to have something like&lt;BR /&gt;
source=a[1-3]* | stats …&lt;/P&gt;

&lt;P&gt;to use a1.gz, a2.gz and a3.gz as source but it does not accept [1-3] and gives error.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2013 19:10:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137308#M37608</guid>
      <dc:creator>gimbil</dc:creator>
      <dc:date>2013-11-11T19:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression in source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137309#M37609</link>
      <description>&lt;P&gt;The &lt;CODE&gt;search&lt;/CODE&gt; command does not support filtering using regexes. You'll either have to filter using wildcards and/or explicit individual terms, or use the separate &lt;CODE&gt;regex&lt;/CODE&gt; operator as your second command, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=a* | regex source="a[1-3]*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The drawback to this approach is that Splunk will read all events matching &lt;CODE&gt;source=a*&lt;/CODE&gt; first before sending them to the &lt;CODE&gt;regex&lt;/CODE&gt; command that then performs the filtering, which means more events will be read from disk than what is strictly necessary.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2013 19:27:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137309#M37609</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-11-11T19:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression in source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137310#M37610</link>
      <description>&lt;P&gt;You can use wildcards in the source specifier, but (AFAIK) not regex.  So '&lt;CODE&gt;source="a*.gz" | ...&lt;/CODE&gt;' should work.&lt;/P&gt;

&lt;P&gt;There's also '&lt;CODE&gt;| where like(source,"a%.gz") | ...&lt;/CODE&gt;', but that's still not regex and is probably less efficient.&lt;/P&gt;

&lt;P&gt;Finally, you can try '&lt;CODE&gt;| regex source="a[0-9]+.gz" | stats ...&lt;/CODE&gt;', but that's probably still less efficient that the first option.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2013 19:32:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137310#M37610</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2013-11-11T19:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression in source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137311#M37611</link>
      <description>&lt;P&gt;Sorry but for some reason source=a* | regex source="b" is still returning everything and not filtering at all. Am I missing something?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2013 19:36:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137311#M37611</guid>
      <dc:creator>gimbil</dc:creator>
      <dc:date>2013-11-11T19:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression in source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137312#M37612</link>
      <description>&lt;P&gt;No that looks about right, depending on how your filter looks more exactly and what sources you expect to be filtered out.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2013 20:04:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137312#M37612</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-11-11T20:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression in source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137313#M37613</link>
      <description>&lt;P&gt;Ayn did not say "b".  I would refine her answer to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=a* | regex source="a[1-3].gz"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Sep 2015 19:44:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137313#M37613</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-10T19:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression in source</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137314#M37614</link>
      <description>&lt;P&gt;Best option is to use the wildcard to get you filter done, as specified by @Ayn and @richgalloway. The regex options may be inefficient based on your data distribution among the source and filter, however, another option that you can try is to specify the required source name in the base search, using subsearch, something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah [| metadata type=sources index=blah | table source | regex source="a[1-3].gz" ] | rest of the search
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The subsearch will grab all the required source (a1.gz/a2.gz/a3.gz in your example) and generate an OR condition into the base search, so effectively your search will become:- &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=blah ((source=a1.gz) OR (source=a2.gz) OR (source=a3.gz)) | rest of the search
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Sep 2015 21:06:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-expression-in-source/m-p/137314#M37614</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-10T21:06:56Z</dc:date>
    </item>
  </channel>
</rss>

