<?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 variable in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453881#M128437</link>
    <description>&lt;P&gt;Also note that both &lt;CODE&gt;match()&lt;/CODE&gt; and &lt;CODE&gt;replace()&lt;/CODE&gt; will pull RegEx from inside of a field name.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jul 2019 19:38:29 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-07-02T19:38:29Z</dc:date>
    <item>
      <title>Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453873#M128429</link>
      <description>&lt;P&gt;I would like to store a regex pattern in a variable and use it to extract data.  I've seen lots of similar questions but haven't been able to figure this out.&lt;/P&gt;

&lt;P&gt;I can do the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 | eval val=4 | rex field=val "(?&amp;lt;dig&amp;gt;\d)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but I cannot &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 | eval val=4 | eval ptn="(?&amp;lt;dig&amp;gt;\d)" | rex field=val ptn
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ultimately, I would have regex patterns stored in a CSV file and use lookup to get the correct pattern for a given query.  It seems the above would a minimal implementation of this strategy.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 10:20:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453873#M128429</guid>
      <dc:creator>bobweinerjr</dc:creator>
      <dc:date>2019-07-02T10:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453874#M128430</link>
      <description>&lt;P&gt;You can use map&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval val=4 
| eval ptn="(?&amp;lt;dig&amp;gt;\d)" 
| map [ search | rex field=val $ptn$]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 12:18:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453874#M128430</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-07-02T12:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453875#M128431</link>
      <description>&lt;P&gt;Didn't know about map.  That seems useful. &lt;/P&gt;

&lt;P&gt;This search did not work for me, though. &lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 12:41:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453875#M128431</guid>
      <dc:creator>bobweinerjr</dc:creator>
      <dc:date>2019-07-02T12:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453876#M128432</link>
      <description>&lt;P&gt;You could use a transforms.conf stanza with the &lt;STRONG&gt;extract&lt;/STRONG&gt; command to accomplish this.&lt;BR /&gt;
Transforms would be your &lt;EM&gt;storage&lt;/EM&gt; for your regex pattern and then you'd invoke it with &lt;STRONG&gt;extract&lt;/STRONG&gt; during your search, or you can apply it automatically in props.conf&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.5.2/SearchReference/Extract"&gt;https://docs.splunk.com/Documentation/Splunk/6.5.2/SearchReference/Extract&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 13:24:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453876#M128432</guid>
      <dc:creator>oscar84x</dc:creator>
      <dc:date>2019-07-02T13:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453877#M128433</link>
      <description>&lt;P&gt;It would actually be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval val=4 
| eval ptn="(?&amp;lt;dig&amp;gt;\d)"
| map search="| rex field=val $ptn$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Except that the search results don't go into the map command for &lt;CODE&gt;val&lt;/CODE&gt; in that way, and you can't send the &lt;CODE&gt;val&lt;/CODE&gt; value into the search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval val=4 
| eval ptn="(?&amp;lt;dig&amp;gt;\d)"
| map search="| rex field=$val$ $ptn$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;because the &lt;CODE&gt;val&lt;/CODE&gt; value isn't a field name. So you are stuck between a rock and a hard place. The &lt;CODE&gt;rex&lt;/CODE&gt; command requires a quoted string for the regex that it will use, not a field. I don't know of a way that you can do what you are wanting to do.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 13:46:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453877#M128433</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2019-07-02T13:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453878#M128434</link>
      <description>&lt;P&gt;This is probably more what you are looking for:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/386488/regex-in-lookuptable.html"&gt;https://answers.splunk.com/answers/386488/regex-in-lookuptable.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 14:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453878#M128434</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-02T14:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453879#M128435</link>
      <description>&lt;P&gt;I always mess up the syntax of map... apologies&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 17:01:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453879#M128435</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-07-02T17:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453880#M128436</link>
      <description>&lt;P&gt;quite alright.  I appreciate the input and will learn from it anyway.&lt;BR /&gt;
unfortunately, we had a power outage on campus this morning and Splunk is not the first thing restored so it won't be today &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 18:13:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453880#M128436</guid>
      <dc:creator>bobweinerjr</dc:creator>
      <dc:date>2019-07-02T18:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453881#M128437</link>
      <description>&lt;P&gt;Also note that both &lt;CODE&gt;match()&lt;/CODE&gt; and &lt;CODE&gt;replace()&lt;/CODE&gt; will pull RegEx from inside of a field name.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 19:38:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453881#M128437</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-02T19:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453882#M128438</link>
      <description>&lt;P&gt;Here's what I meant to post:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults count=1 
 | eval val=4 
 | eval ptn="(?&amp;lt;dig&amp;gt;\d)" 
 | map search="search index=yourindex | rex field=val $ptn$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | inputlookup yourlookup.csv 
 | map search="search index=yourindex | rex field=val $regexFieldInLookup$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 20:05:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453882#M128438</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-07-02T20:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453883#M128439</link>
      <description>&lt;P&gt;That's great.  Going to try that out.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 20:07:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453883#M128439</guid>
      <dc:creator>bobweinerjr</dc:creator>
      <dc:date>2019-07-04T20:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Regex from variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453884#M128440</link>
      <description>&lt;P&gt;Be sure to &lt;CODE&gt;UpVote&lt;/CODE&gt; over there and come back here to &lt;CODE&gt;Accept&lt;/CODE&gt; an answer if it works out.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 13:46:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-from-variable/m-p/453884#M128440</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-05T13:46:29Z</dc:date>
    </item>
  </channel>
</rss>

