<?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: Pass a token to regex or pass a field to regex in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561467#M195330</link>
    <description>&lt;P&gt;&lt;BR /&gt;| rex max_match=0 field=_raw "(?&amp;lt;extractedfieldname&amp;gt;(17|7|1))"&lt;BR /&gt;&lt;BR /&gt;this will work but will still need the variable to be passed to this rex&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jul 2021 00:28:43 GMT</pubDate>
    <dc:creator>spicy</dc:creator>
    <dc:date>2021-07-30T00:28:43Z</dc:date>
    <item>
      <title>Pass a token to regex or pass a field to regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561443#M195324</link>
      <description>&lt;P&gt;I am extracting a list of free text string in the _ raw and creating a new field.&lt;BR /&gt;The list of terms comes from user input, on the search input of a dashboard.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I cant seem to find how to place the token/variable in the regex... probably something easy im missing.&lt;BR /&gt;&lt;BR /&gt;$token$="test|google|domain|badguy"&amp;nbsp; &amp;nbsp; &amp;nbsp; (formmated this way so regex can see it as OR separated list)&lt;BR /&gt;rex field=_raw " (?&amp;lt;extractedfieldname&amp;gt;$token$) (does not work)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Is there a way to do this?&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;if not a token option, can i:&lt;/P&gt;&lt;P&gt;eval tokenname=$token$&lt;BR /&gt;&lt;SPAN&gt;rex field=_raw " (?&amp;lt;extractedfieldname&amp;gt;'tokenname') (does not work)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;After the token/variable is placed correctly this is the search format im looking for:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;rex field=_raw " (?&amp;lt;extractedfieldname&amp;gt;test|google|domain|badguy) (this does work)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;thanks for any help!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 20:34:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561443#M195324</guid>
      <dc:creator>spicy</dc:creator>
      <dc:date>2021-07-29T20:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a token to regex or pass a field to regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561450#M195325</link>
      <description>&lt;P&gt;You could try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="test|google|domain|badguy|something else"
| eval event=split(_raw,"|")
| mvexpand event
| eval _raw="random text ".event." other random text"
| fields - event _time



| eval search="test|google|domain|badguy"
| eval extractedfieldname=replace(_raw,"(?:.*)(?&amp;lt;t&amp;gt;".search.")(?:.*)","\1")
| eval extractedfieldname=if(extractedfieldname=_raw,null(),extractedfieldname)&lt;/LI-CODE&gt;&lt;P&gt;The first part (before the blank lines) sets up some sample dummy events.&lt;/P&gt;&lt;P&gt;The second part sets a field to be the regex you want (could be from a token), then uses&amp;nbsp; replace to extract the matching string from _raw. If there is no match, the matched string is equal to _raw so this just needs to be replaced with null in this instance.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 21:35:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561450#M195325</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-07-29T21:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a token to regex or pass a field to regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561461#M195328</link>
      <description>&lt;P&gt;with the replace is it only gonna show me one hit from the passed list or does it need to be appended in some way?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 23:40:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561461#M195328</guid>
      <dc:creator>spicy</dc:creator>
      <dc:date>2021-07-29T23:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a token to regex or pass a field to regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561467#M195330</link>
      <description>&lt;P&gt;&lt;BR /&gt;| rex max_match=0 field=_raw "(?&amp;lt;extractedfieldname&amp;gt;(17|7|1))"&lt;BR /&gt;&lt;BR /&gt;this will work but will still need the variable to be passed to this rex&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 00:28:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561467#M195330</guid>
      <dc:creator>spicy</dc:creator>
      <dc:date>2021-07-30T00:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a token to regex or pass a field to regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561497#M195339</link>
      <description>&lt;P&gt;Yes you are going to get one hit (which is what your examples were doing); in this case it will be the last one. If you want the first one add a ? to the first unnamed group&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval extractedfieldname=replace(_raw,"(?:.*?)(?&amp;lt;t&amp;gt;".search.")(?:.*)","\1")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 06:38:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-token-to-regex-or-pass-a-field-to-regex/m-p/561497#M195339</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-07-30T06:38:46Z</dc:date>
    </item>
  </channel>
</rss>

