<?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: How do you use value or capture groups as regex's curly bracket number parameter? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396341#M115085</link>
    <description>&lt;P&gt;I downvoted this post because the answer is plain wrong - please test your suggestions before posting.&lt;BR /&gt;
here is a search i ran to check your answer:&lt;BR /&gt;
&lt;CODE&gt;| makeresults | eval test="abc5defghijk" | rex field=test "\d{1}+(?&amp;lt;sub&amp;gt;.\s{3})"&lt;/CODE&gt;&lt;BR /&gt;
you can change that digit 5 inside test to any other digit you want and sub will always be "defg".&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jan 2019 22:48:23 GMT</pubDate>
    <dc:creator>arkadyz1</dc:creator>
    <dc:date>2019-01-16T22:48:23Z</dc:date>
    <item>
      <title>How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396330#M115074</link>
      <description>&lt;P&gt;In the code below, i want the explicit {5} to be replaced with a variable like {$session_length$}. Is this possible? If so, how? Thanks!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test="abc5defgHijk" 
| rex field=test "^.{3}(?&amp;lt;session_length&amp;gt;\d)(?&amp;lt;session&amp;gt;.{5})"
|fields session
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want the output of session="defgH". &lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2019 18:33:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396330#M115074</guid>
      <dc:creator>mschaaf</dc:creator>
      <dc:date>2019-01-10T18:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396331#M115075</link>
      <description>&lt;P&gt;To get 'defgH" you can use below rex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=test "\d{1}+(?&amp;lt;sub&amp;gt;.\S{3})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Jan 2019 23:01:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396331#M115075</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-01-10T23:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396332#M115076</link>
      <description>&lt;P&gt;Mschaaf,&lt;/P&gt;

&lt;P&gt;As far as I know, the REX command doesn't support a variable for the regex parameter.  Can you give us an example of your data?&lt;BR /&gt;
There might be other ways to do what you want to do?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:10:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396332#M115076</guid>
      <dc:creator>ccl0utier</dc:creator>
      <dc:date>2019-01-11T13:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396333#M115077</link>
      <description>&lt;P&gt;I'm with &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/148397"&gt;@ccl0utier&lt;/a&gt;k on this one - there is no way to grab that with just one &lt;CODE&gt;rex&lt;/CODE&gt; command. You need a longer way: extract session_length first via &lt;CODE&gt;eval&lt;/CODE&gt; or &lt;CODE&gt;rex&lt;/CODE&gt; command first then use &lt;CODE&gt;| eval session=substr(test,5,session_length)&lt;/CODE&gt; (where 5 is the position where session starts, 1-based so it skips the first 4 characters) to get the session.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:45:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396333#M115077</guid>
      <dc:creator>arkadyz1</dc:creator>
      <dc:date>2020-09-29T22:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396334#M115078</link>
      <description>&lt;P&gt;Indeed, this is where I was leading.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 19:58:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396334#M115078</guid>
      <dc:creator>ccl0utier</dc:creator>
      <dc:date>2019-01-11T19:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396335#M115079</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test="abc5defgHijk" 
| rex field=test "^.{3}(?&amp;lt;session_length&amp;gt;\d)"
| eval {session_length} = session_length
| foreach 1* 2* 3* 4* 5* 6* 7* 8* 9*
    [ rex field=test "^.{3}(?&amp;lt;session_length&amp;gt;\d)(?&amp;lt;session&amp;gt;.{&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;})" ]
| fields - 0 1 2 3 4 5 6 7 8 9
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Jan 2019 20:18:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396335#M115079</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-11T20:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396336#M115080</link>
      <description>&lt;P&gt;Cool challenge; thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 20:18:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396336#M115080</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-11T20:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396337#M115081</link>
      <description>&lt;P&gt;Look at my solution.  It actually works &lt;EM&gt;exactly&lt;/EM&gt; as you would like, @mschaaf, without the downsides of this answer.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 20:05:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396337#M115081</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-16T20:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396338#M115082</link>
      <description>&lt;P&gt;Unless there are other fields in the original event, starting with a digit, correct?&lt;/P&gt;

&lt;P&gt;I like the elegance of your answer, but what are the downsides of mine?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:13:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396338#M115082</guid>
      <dc:creator>arkadyz1</dc:creator>
      <dc:date>2019-01-16T22:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396339#M115083</link>
      <description>&lt;P&gt;You have hard-coded the &lt;CODE&gt;5&lt;/CODE&gt;, mine gets it from a a field, which is what the OP, @mschaaf, was asking.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:18:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396339#M115083</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-16T22:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396340#M115084</link>
      <description>&lt;P&gt;No, I did not hard-code the length - 5 was the length of the prefix (.{3}\d)+1 (substr is 1-based), the other 5 gets taken from session_length - look closer :). My solution will take 'defg' from 'abc4defgHijk' - please check.&lt;BR /&gt;
Here is a search I've just run:&lt;BR /&gt;
&lt;CODE&gt;| makeresults | eval test="abc4defgHijk" | rex field=test "^.{3}(?&amp;lt;session_length&amp;gt;\d)" | eval session=substr(test,5,session_length)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:47:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396340#M115084</guid>
      <dc:creator>arkadyz1</dc:creator>
      <dc:date>2020-09-29T22:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396341#M115085</link>
      <description>&lt;P&gt;I downvoted this post because the answer is plain wrong - please test your suggestions before posting.&lt;BR /&gt;
here is a search i ran to check your answer:&lt;BR /&gt;
&lt;CODE&gt;| makeresults | eval test="abc5defghijk" | rex field=test "\d{1}+(?&amp;lt;sub&amp;gt;.\s{3})"&lt;/CODE&gt;&lt;BR /&gt;
you can change that digit 5 inside test to any other digit you want and sub will always be "defg".&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:48:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396341#M115085</guid>
      <dc:creator>arkadyz1</dc:creator>
      <dc:date>2019-01-16T22:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396342#M115086</link>
      <description>&lt;P&gt;My mistake, I misread your solution.  I see it now.  I will delete my entire comment thread tomorrow.  Thanks for setting me straight.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:48:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396342#M115086</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-16T22:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396343#M115087</link>
      <description>&lt;P&gt;I see that. Thanks for letting me know .&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:59:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396343#M115087</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-01-16T22:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396344#M115088</link>
      <description>&lt;P&gt;No, please don't. It shows the weakness anyway: how do I make it more generic and &lt;STRONG&gt;calculate&lt;/STRONG&gt; the starting offset instead of hard-coding it? I actually hate seeing those constants in the code. I'd say something like&lt;BR /&gt;
&lt;CODE&gt;| rex field=test "(?&amp;lt;prefix&amp;gt;.{3})(?&amp;lt;session_length&amp;gt;\d)" | eval session=substr(test,1+len(prefix)+len(session_length),session_length)&lt;/CODE&gt;&lt;BR /&gt;
is more to my liking. How's that for a solution?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 02:54:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396344#M115088</guid>
      <dc:creator>arkadyz1</dc:creator>
      <dc:date>2019-01-17T02:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396345#M115089</link>
      <description>&lt;P&gt;I like it just as much as mine.  Let's &lt;CODE&gt;UpVote&lt;/CODE&gt; eachother and agree to a draw.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 03:07:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396345#M115089</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-17T03:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396346#M115090</link>
      <description>&lt;P&gt;I upvoted yours quite some time ago. Also, it's not a competition - there is more than one way to do something, and it's great. I actually learned something from your answer - never used &lt;CODE&gt;foreach&lt;/CODE&gt; command, nor &lt;CODE&gt;{{session_length}}&lt;/CODE&gt; syntax, and just being aware of it is great.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 14:20:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396346#M115090</guid>
      <dc:creator>arkadyz1</dc:creator>
      <dc:date>2019-01-17T14:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396347#M115091</link>
      <description>&lt;P&gt;Most people do not know that &lt;CODE&gt;replace&lt;/CODE&gt; can take values out of fields for it's arguments.  It is a &lt;EM&gt;very&lt;/EM&gt; special command in that regard and a super powerful tool for this kind of thing.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 17:04:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/396347#M115091</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-18T17:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use value or capture groups as regex's curly bracket number parameter?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/602358#M209659</link>
      <description>&lt;P&gt;Here's another (late) solution.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval test="abc5defgHijk" 
| eval session=substr( replace(test,"^.{3}\d",""),
    1, tonumber(replace(test,"^.{3}(\d).*","\1")) )
|fields session&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 05:00:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-value-or-capture-groups-as-regex-s-curly-bracket/m-p/602358#M209659</guid>
      <dc:creator>scombs</dc:creator>
      <dc:date>2022-06-20T05:00:44Z</dc:date>
    </item>
  </channel>
</rss>

