<?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: Splunk bug: string replace function fails if the string to be replaced starts with &amp;quot;+&amp;quot; character in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631383#M219294</link>
    <description>&lt;P&gt;The extraction works because the extracted string is not processed as a regex (until you put it in the replace function).&lt;/P&gt;&lt;P&gt;You could try something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex mode=sed field=ph1 "s/([\+\\\*\{\}\[\]\.\(\)\|\?])/#\#\1/g"
| rex mode=sed field=ph1 "s/#//g"
| eval message2 = replace(message, ph1, ph2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2023 17:54:56 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-02-17T17:54:56Z</dc:date>
    <item>
      <title>Splunk bug: string replace function fails if the string to be replaced starts with "+" character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631363#M219286</link>
      <description>&lt;P&gt;replace() function produce an empty string if the string to be replaced starts with a "+" character.&lt;/P&gt;&lt;P&gt;this search with replace() works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval message = "This is mark1 replacement mark2", ph2="different" 
| rex field=message "mark1 (?&amp;lt;ph1&amp;gt;[^/s]*) mark2" 
| eval message2 = replace(message, ph1, ph2)
| table message, message2, ph1, ph2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dev999_1-1676651078169.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23935i57034BDAF61AE5B2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Dev999_1-1676651078169.png" alt="Dev999_1-1676651078169.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;this one will produce an empty message2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval message = "This is mark1 +replacement mark2", ph2="different" 
| rex field=message "mark1 (?&amp;lt;ph1&amp;gt;[^/s]*) mark2" 
| eval message2 = replace(message, ph1, ph2)
| table message, message2, ph1, ph2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dev999_0-1676651034277.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23934i477ACF3EA5A3FC5E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Dev999_0-1676651034277.png" alt="Dev999_0-1676651034277.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 16:28:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631363#M219286</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2023-02-17T16:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk bug: string replace function fails if the string to be replaced starts with "+" character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631367#M219287</link>
      <description>&lt;P&gt;The replace function treats the string to be replaced as a regex - "+" is a special character in regex and because it isn't preceded by anything, this makes the regex invalid, hence, it does perform as expected.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 16:48:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631367#M219287</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-17T16:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk bug: string replace function fails if the string to be replaced starts with "+" character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631369#M219288</link>
      <description>&lt;P&gt;the function should have ways to escape the special characters. As you can see above, the extraction rex has no problem handling it.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 17:02:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631369#M219288</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2023-02-17T17:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk bug: string replace function fails if the string to be replaced starts with "+" character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631383#M219294</link>
      <description>&lt;P&gt;The extraction works because the extracted string is not processed as a regex (until you put it in the replace function).&lt;/P&gt;&lt;P&gt;You could try something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex mode=sed field=ph1 "s/([\+\\\*\{\}\[\]\.\(\)\|\?])/#\#\1/g"
| rex mode=sed field=ph1 "s/#//g"
| eval message2 = replace(message, ph1, ph2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 17:54:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-bug-string-replace-function-fails-if-the-string-to-be/m-p/631383#M219294</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-17T17:54:56Z</dc:date>
    </item>
  </channel>
</rss>

