<?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: Text function replace and &amp;quot;\&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Text-function-replace-and-quot-quot/m-p/400482#M116034</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval user="qwerty\foo" 
| eval ruser=replace(user,"\\\\","\\\\\\\\")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In SPL, the escape has to be escaped so everything doubles.  If you want to find a backlash, you would normally look for \.  But in SPL you have to escape your escape: \ and then escape the backslash you are trying to find with another \.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/Search/SPLandregularexpressions"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.0/Search/SPLandregularexpressions&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2019 16:14:24 GMT</pubDate>
    <dc:creator>justinatpnnl</dc:creator>
    <dc:date>2019-07-18T16:14:24Z</dc:date>
    <item>
      <title>Text function replace and "\"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Text-function-replace-and-quot-quot/m-p/400481#M116033</link>
      <description>&lt;P&gt;Hello folks,&lt;/P&gt;

&lt;P&gt;I am experiencing problems to use replace to change a field value like "qwerty\foo" to "qwerty\foo".&lt;/P&gt;

&lt;P&gt;I am testing it with this query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | makeresults
    | eval user="qwerty\foo"
    | eval ruser=replace(user,"\\","\\")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this case I have this error &lt;BR /&gt;
Error in 'eval' command: Regex: \ at end of pattern&lt;/P&gt;

&lt;P&gt;The same for:&lt;BR /&gt;
| eval ruser=replace(user,"\","\\")&lt;/P&gt;

&lt;P&gt;Using | eval ruser=replace(user,"\{1}","anything") , It does not show an error but nothing changes. The same for + or *.&lt;/P&gt;

&lt;P&gt;Using | eval ruser=replace(user,"\\","a") shows the next error, and of course If use another " nothing will change.&lt;BR /&gt;
Unbalanced quotes.&lt;/P&gt;

&lt;P&gt;With | eval ruser=replace(user,"(.&lt;EM&gt;)\(.&lt;/EM&gt;)","\1\\\2") no error but nothing changes and | eval ruser=replace(user,"(.&lt;EM&gt;)\(.&lt;/EM&gt;)","\1\\\2") shows the next error: &lt;BR /&gt;
Error in 'eval' command: Regex: unmatched closing parenthesis&lt;/P&gt;

&lt;P&gt;Just in case tested | eval ruser=replace(user,"/\","/\/\") , error&lt;BR /&gt;
Error in 'eval' command: The expression is malformed. An unexpected character is reached at '\/\")'.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;The only thing worked for reading \ was this regex:&lt;BR /&gt;
| eval ruser=replace(user,"(.&lt;EM&gt;)\(.&lt;/EM&gt;)","\1(\)(\)\2")&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;But the output I was unable to output a double \ &lt;/P&gt;

&lt;P&gt;Because I am unable to rex it a temporary solution was this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval user="qwerty\foo"
| eval tuser=replace(user,"(.*)\\\(.*)","\1?\2")
| rex field=tuser "(?&amp;lt;u1&amp;gt;[^\?]+)\?(?&amp;lt;u2&amp;gt;[^\?]+)"
| eval ruser=u1+"\\\\"+u2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;¿Someone know the way to use replace in this case to make things easy? Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 15:59:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Text-function-replace-and-quot-quot/m-p/400481#M116033</guid>
      <dc:creator>osakachan</dc:creator>
      <dc:date>2019-07-18T15:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Text function replace and "\"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Text-function-replace-and-quot-quot/m-p/400482#M116034</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval user="qwerty\foo" 
| eval ruser=replace(user,"\\\\","\\\\\\\\")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In SPL, the escape has to be escaped so everything doubles.  If you want to find a backlash, you would normally look for \.  But in SPL you have to escape your escape: \ and then escape the backslash you are trying to find with another \.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/Search/SPLandregularexpressions"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.0/Search/SPLandregularexpressions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 16:14:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Text-function-replace-and-quot-quot/m-p/400482#M116034</guid>
      <dc:creator>justinatpnnl</dc:creator>
      <dc:date>2019-07-18T16:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Text function replace and "\"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Text-function-replace-and-quot-quot/m-p/400483#M116035</link>
      <description>&lt;P&gt;So many banelings!!err.. I mean, \\\\\ &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Works as intended, I did not understand the double scape so I've used 3 \ instead of 4 \ &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks for the answer.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 07:36:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Text-function-replace-and-quot-quot/m-p/400483#M116035</guid>
      <dc:creator>osakachan</dc:creator>
      <dc:date>2019-07-19T07:36:19Z</dc:date>
    </item>
  </channel>
</rss>

