<?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: Using regex to replace letters in a search. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31570#M6530</link>
    <description>&lt;P&gt;Or just &lt;BR /&gt;
| search newName&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2013 11:22:30 GMT</pubDate>
    <dc:creator>antlefebvre</dc:creator>
    <dc:date>2013-08-13T11:22:30Z</dc:date>
    <item>
      <title>Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31563#M6523</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm performing a search using advanced xml that returns a key/value pair (among other things).&lt;/P&gt;

&lt;P&gt;E.g. Filename=someName123.jpg &lt;/P&gt;

&lt;P&gt;I use the Filename key to perform a few searches, e.g. $Filename$ in a child module. Following that I need to slightly change the name and continue a new search. The name requires the addition of a few numbers and a change of the extension. &lt;/P&gt;

&lt;P&gt;E.g. someName123-456.bmp&lt;/P&gt;

&lt;P&gt;So I've been trying to work out the best/easiest way to change the name. I've attempted some regex ("rex" and "rex mode=sed") and am failing dismally, purely due to my inability to grasp the regex syntax I think). I also had a brief look at eval replace option, but struggled to understand its operation (as shown here : &lt;A href="http://splunk-base.splunk.com/answers/6424/replace-parts-of-a-string"&gt;http://splunk-base.splunk.com/answers/6424/replace-parts-of-a-string&lt;/A&gt;).&lt;/P&gt;

&lt;P&gt;If anyone can help with this it would be much appreciated. Also if someone does provide a regex answer, could you please explain how it does what it does, or point me to a page so I can reverse engineer the regex syntax to understand how it does what it does?&lt;/P&gt;

&lt;P&gt;Thank you in advance..&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2013 10:28:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31563#M6523</guid>
      <dc:creator>kisa</dc:creator>
      <dc:date>2013-08-12T10:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31564#M6524</link>
      <description>&lt;P&gt;I was about to write an answer, but it would help if you could specify exactly how you want things to be transformed. Which parts of this are static and which are dynamic? Is "someName" always the same or not? Is there a rule to the numbers you want to add after the dash you're inserting in the filename? Should the extension always be changed from .jpg to .bmp?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2013 11:15:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31564#M6524</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-08-12T11:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31565#M6525</link>
      <description>&lt;P&gt;Thanks for the quick reply.&lt;/P&gt;

&lt;P&gt;someName - will always be the same (static).&lt;BR /&gt;
123 - will be consistent across the name change, but each someName file will have a new/different number e.g. 124.&lt;BR /&gt;
It will always be a change from .jpg to 456.bmp (456 being consistent).&lt;/P&gt;

&lt;P&gt;So I was trying to do something like:-&lt;/P&gt;

&lt;P&gt;someName123.jpg to someName123-456.bmp&lt;/P&gt;

&lt;P&gt;regex to replace .jpg (everything from the "." onward and inclusive or 4 characters back from the end of the string) with "-456.bmp". Which sounds simple, but I couldn't for the life of me work out the regex to do it &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2013 11:51:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31565#M6525</guid>
      <dc:creator>kisa</dc:creator>
      <dc:date>2013-08-12T11:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31566#M6526</link>
      <description>&lt;P&gt;Unsure of how to post code in comment, so I'm asking in answer.&lt;/P&gt;

&lt;P&gt;Does it have to be in a regex or can you do this replacement in a search? Ex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | eval newfilename=$filename$ | replace *.jpg with *-456.bmp in newfilename
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2013 14:04:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31566#M6526</guid>
      <dc:creator>antlefebvre</dc:creator>
      <dc:date>2013-08-12T14:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31567#M6527</link>
      <description>&lt;P&gt;Thanks for the suggestion, it looks like it should work, though I can't get it to work :(. I added the eval and replace to a few searches but found they made no difference to the search. The search just returned what was set before the eval. What am I missing? Here is the last test I did:-&lt;/P&gt;

&lt;P&gt;index=_internal | eval newName=$series$ | replace *web_access.log with *metrics.log in newName&lt;/P&gt;

&lt;P&gt;It just returns everything filtered by "index=_internal", which is pretty much everything.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:33:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31567#M6527</guid>
      <dc:creator>kisa</dc:creator>
      <dc:date>2020-09-28T14:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31568#M6528</link>
      <description>&lt;P&gt;Sorry, after some clarification I also found out that the value before the .bmp (i.e. 456) is not a constant.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2013 09:36:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31568#M6528</guid>
      <dc:creator>kisa</dc:creator>
      <dc:date>2013-08-13T09:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31569#M6529</link>
      <description>&lt;P&gt;I was illustrating the replace function. Your search is stating you want to see everything in _internal. You'll want to add this to the end of the search:&lt;BR /&gt;
| search whatyourelookingfor=newName&lt;/P&gt;

&lt;P&gt;if I am understanding what you are trying to do correctly.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2013 11:03:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31569#M6529</guid>
      <dc:creator>antlefebvre</dc:creator>
      <dc:date>2013-08-13T11:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31570#M6530</link>
      <description>&lt;P&gt;Or just &lt;BR /&gt;
| search newName&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2013 11:22:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31570#M6530</guid>
      <dc:creator>antlefebvre</dc:creator>
      <dc:date>2013-08-13T11:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31571#M6531</link>
      <description>&lt;P&gt;Thanks again. &lt;/P&gt;

&lt;P&gt;I tried:-&lt;/P&gt;

&lt;P&gt;| search newName&lt;/P&gt;

&lt;P&gt;and the search found nothing.  I tried a :-&lt;/P&gt;

&lt;P&gt;| table newName&lt;/P&gt;

&lt;P&gt;and it displayed the correct name it should be searching for. Is there any reason why the search isn't working with the new eval/replace field name (using the same name in a standard Splunk search worked fine)?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2013 10:32:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31571#M6531</guid>
      <dc:creator>kisa</dc:creator>
      <dc:date>2013-08-14T10:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31572#M6532</link>
      <description>&lt;P&gt;Ah. Sorry. Search newName will literally search for the term newName whereas you want to search for its value.  I am unsure how to extract the value from newName to pipe into a new search.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2013 12:29:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31572#M6532</guid>
      <dc:creator>antlefebvre</dc:creator>
      <dc:date>2013-08-14T12:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using regex to replace letters in a search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31573#M6533</link>
      <description>&lt;P&gt;No worries, thanks for your help so far. I'll see if I can finish it off &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2013 10:30:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-regex-to-replace-letters-in-a-search/m-p/31573#M6533</guid>
      <dc:creator>kisa</dc:creator>
      <dc:date>2013-08-15T10:30:19Z</dc:date>
    </item>
  </channel>
</rss>

