<?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 to get position of a not constant char/substring in another string? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144831#M40333</link>
    <description>&lt;P&gt;It is possible to pass argument between a form input and a search string in a form dashboard.&lt;BR /&gt;
You may try this approach. the variable will look like $searchField$&lt;/P&gt;

&lt;P&gt;see &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.3/Viz/Buildandeditforms#Basic_form_example"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.3/Viz/Buildandeditforms#Basic_form_example&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Remark, your regex is not valid, you have non escaped double quotes in it..&lt;/P&gt;</description>
    <pubDate>Mon, 28 Apr 2014 14:36:13 GMT</pubDate>
    <dc:creator>yannK</dc:creator>
    <dc:date>2014-04-28T14:36:13Z</dc:date>
    <item>
      <title>How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144830#M40332</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;

&lt;P&gt;As I understand, Splunk doesn't have any special functions for normal work with string.&lt;BR /&gt;
I need to get index of a not constant char/substring in another string.&lt;BR /&gt;
&lt;STRONG&gt;Substring is not constant&lt;/STRONG&gt;, it's value from another field.&lt;/P&gt;

&lt;P&gt;Solution for constant substring: &lt;A href="http://answers.splunk.com/answers/66496/how-to-get-index-of-a-particular-letter-in-string"&gt;http://answers.splunk.com/answers/66496/how-to-get-index-of-a-particular-letter-in-string&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;But, it has not work for dynamic substring. I tried to form regular expression:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="b2b_integration_oss"
| eval string="Some long string"
| eval regExString=".*(?&amp;lt;substring&amp;gt;\b" + searchField + "\b).*"
| rex field=string regExString
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, I got next error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'rex' command: The regex 'regExString' does not extract anything. It should specify at least one named group. Format: (?&amp;lt;name&amp;gt;...).
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Why&lt;/STRONG&gt; doesn't exist in Splunk any analogs for SQL CHARINDEX function?&lt;/P&gt;

&lt;P&gt;Anyone can guide me please on this?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Apr 2014 13:42:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144830#M40332</guid>
      <dc:creator>Nikita_Danilov</dc:creator>
      <dc:date>2014-04-28T13:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144831#M40333</link>
      <description>&lt;P&gt;It is possible to pass argument between a form input and a search string in a form dashboard.&lt;BR /&gt;
You may try this approach. the variable will look like $searchField$&lt;/P&gt;

&lt;P&gt;see &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.3/Viz/Buildandeditforms#Basic_form_example"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.3/Viz/Buildandeditforms#Basic_form_example&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Remark, your regex is not valid, you have non escaped double quotes in it..&lt;/P&gt;</description>
      <pubDate>Mon, 28 Apr 2014 14:36:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144831#M40333</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2014-04-28T14:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144832#M40334</link>
      <description>&lt;P&gt;Can you attach an example of the event, and the expected result ?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Apr 2014 14:38:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144832#M40334</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2014-04-28T14:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144833#M40335</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval haystack = "some long string" | eval needle = "some long string foo" | makemv needle | mvexpand needle
| eval replaced = replace(haystack, "(.*?)".needle.".*", "\1") | eval position = if(match(haystack, needle), length(replaced), -1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll yield this result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;haystack           needle   position   replaced
some long string   some            0    
some long string   long            5   some
some long string   string         10   some long
some long string   foo            -1   some long string 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You'll get &lt;CODE&gt;position=-1&lt;/CODE&gt; if the needle is not contained in the haystack, and its first position if it is. Remove the non-greedy question mark from the regex to get the last position. Note, you may get unexpected results if the needle contains special regex characters.&lt;/P&gt;

&lt;P&gt;For performance optimization you should move the replace into the then-branch of the if to avoid unnecessary regex'ing in case of non-matches - I've left it there for easy understanding of the steps involved.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Apr 2014 20:04:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144833#M40335</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-28T20:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144834#M40336</link>
      <description>&lt;P&gt;Martin, it works fine for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval replaced = replace(haystack, "(.*?)".needle.".*", "\1")
| eval position = if(match(haystack, needle), length(replaced), -1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;BR /&gt;
Strange to me that there is no special built-in functions.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2014 06:39:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144834#M40336</guid>
      <dc:creator>Nikita_Danilov</dc:creator>
      <dc:date>2014-04-29T06:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144835#M40337</link>
      <description>&lt;P&gt;yannK, thanks, but I need it in basic search, not only in Forms. I've used Martin's solution.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2014 06:43:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144835#M40337</guid>
      <dc:creator>Nikita_Danilov</dc:creator>
      <dc:date>2014-04-29T06:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144836#M40338</link>
      <description>&lt;P&gt;Well, there's pros and cons for having a built-in function for every single use case imaginable. In my mind it clutters the search language tremendously, and doesn't add to the power of the language.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2014 07:56:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144836#M40338</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-29T07:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144837#M40339</link>
      <description>&lt;P&gt;Martin, if there are functions "len" and "substring", why not add another one function for strings as "indexof".&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2014 12:19:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144837#M40339</guid>
      <dc:creator>Nikita_Danilov</dc:creator>
      <dc:date>2014-04-29T12:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144838#M40340</link>
      <description>&lt;P&gt;Beats me... feel free to submit a feature request through a support ticket to get any function added you might need.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2014 13:01:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144838#M40340</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-29T13:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144839#M40341</link>
      <description>&lt;P&gt;There is a combination of built-in functions that can do this in one step. See my answer below.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 15:17:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144839#M40341</guid>
      <dc:creator>timpacl</dc:creator>
      <dc:date>2017-03-31T15:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get position of a not constant char/substring in another string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144840#M40342</link>
      <description>&lt;P&gt;len(mvindex(split(lower([string]),"[char]"),0)). I have submitted an explanatory post below but it still hasn't shown up so here is the formula.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 17:06:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-position-of-a-not-constant-char-substring-in-another/m-p/144840#M40342</guid>
      <dc:creator>timpacl</dc:creator>
      <dc:date>2017-03-31T17:06:11Z</dc:date>
    </item>
  </channel>
</rss>

