<?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 can I escape backslash in a token to modify a search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301239#M90708</link>
    <description>&lt;P&gt;Enclose the entire search string in a CDATA tag, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt; input type="dropdown" token="tzz" searchWhenChanged="true"&amp;gt;
   &amp;lt; choice value="![CDATA[| eval time_splunk=strftime(_time, "%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)")  | eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?&amp;lt;time_offset_seconds&amp;gt;\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, "%s") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)=="+", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , "%Y-%m-%d %H:%M:%S") | eval _time = strptime(time_utc,"%Y-%m-%d %H:%M:%S") ", {}, e.data); }]]&amp;gt;TZ&amp;lt; /choice&amp;gt;
&amp;lt; /input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 08 Jul 2017 18:33:09 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-07-08T18:33:09Z</dc:date>
    <item>
      <title>How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301227#M90696</link>
      <description>&lt;P&gt;I have a search which sometimes I want to do an append, and sometimes not - this should be driven by a dropdown in the GUI. The optional append looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval time_splunk=strftime(_time, "%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)")  | eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, "%s") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)=="+", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , "%Y-%m-%d %H:%M:%S") | eval _time = strptime(time_utc,"%Y-%m-%d %H:%M:%S") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have defined a Dropdown like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt; input type="dropdown" token="tzz" searchWhenChanged="true"&amp;gt;
         &amp;lt; choice value="| eval time_splunk=strftime(_time, "%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)")  | eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?&amp;lt;time_offset_seconds&amp;gt;\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, "%s") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)=="+", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , "%Y-%m-%d %H:%M:%S") | eval _time = strptime(time_utc,"%Y-%m-%d %H:%M:%S") ", {}, e.data); } &amp;gt;TZ&amp;lt; /choice&amp;gt;
&amp;lt; /input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And &lt;CODE&gt;$tzz$&lt;/CODE&gt; goes at the end of my main search.&lt;/P&gt;

&lt;P&gt;My problem is that &lt;CODE&gt;backslashes&lt;/CODE&gt; or rather &lt;CODE&gt;\d&lt;/CODE&gt; in &lt;CODE&gt;| rex field=time_offset ".(?\d{2}:\d{2})" |&lt;/CODE&gt; are not accepted inside the token value. Is there a way of escaping them?&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Edit(Added):&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventHandler.setToken("tzadjust", "| eval time_splunk=strftime(_time, \"%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)\") | eval time_offset=strftime(_time, \"%:z\") | rex field=time_offset \".(?\d{2}:\d{2})\" | eval time_offset_seconds=time_offset_seconds.\":00\" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, \"%s\") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)==\"+\", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , \"%Y-%m-%d %H:%M:%S\") | eval _time = strptime(time_utc,\"%Y-%m-%d %H:%M:%S\") ", {}, e.data);
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is how I set my token and I have to escape &lt;CODE&gt;\d&lt;/CODE&gt; in the &lt;CODE&gt;rex&lt;/CODE&gt; field portion.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:09:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301227#M90696</guid>
      <dc:creator>waltz</dc:creator>
      <dc:date>2017-07-07T13:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301228#M90697</link>
      <description>&lt;P&gt;try doing &lt;CODE&gt;$tzz|s$&lt;/CODE&gt; in your search. to encompass it all in quotes?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:15:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301228#M90697</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-07T13:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301229#M90698</link>
      <description>&lt;P&gt;@waltz, here is the relevant docs page: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Viz/tokens#Token_filters"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Viz/tokens#Token_filters&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:19:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301229#M90698</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-07-07T13:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301230#M90699</link>
      <description>&lt;P&gt;Yeah, I did try that &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/185679"&gt;@cmerriman&lt;/a&gt;. But my search would end up like this: &lt;STRONG&gt;index = myindex| "| eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" "&lt;/STRONG&gt;  which would not yield results to me (throws out an error) .&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:48:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301230#M90699</guid>
      <dc:creator>waltz</dc:creator>
      <dc:date>2020-09-29T14:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301231#M90700</link>
      <description>&lt;P&gt;i just created this token in a test dashboard and receive this error. I didn't escape anything but it came out just fine when i opened it in search. &lt;BR /&gt;
&lt;STRONG&gt;Error in 'rex' command: Encountered the following error while compiling the regex '.(?\d{2}:\d{2})': Regex: unrecognized character after (? or (?-&lt;/STRONG&gt;&lt;BR /&gt;
the regex is looking for a naming group&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=time_offset ".(?&amp;lt;time_offset_seconds&amp;gt;\d{2}:\d{2})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:36:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301231#M90700</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-07T13:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301232#M90701</link>
      <description>&lt;P&gt;Yes, that's what! The regex works fine in a search, but in the dashboard it seems like I have to escape the backslash. Btw, this is not the entire token search which I'm gonna append after my primary search,it's just a small snippet from the token.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:44:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301232#M90701</guid>
      <dc:creator>waltz</dc:creator>
      <dc:date>2017-07-07T13:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301233#M90702</link>
      <description>&lt;P&gt;Thanks you @rjthibod, I did refer this docs page and try them out. But it wouldn't escape the backslash in my token.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:46:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301233#M90702</guid>
      <dc:creator>waltz</dc:creator>
      <dc:date>2017-07-07T13:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301234#M90703</link>
      <description>&lt;P&gt;How about this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt; input type="dropdown" token="tzz" searchWhenChanged="true"&amp;gt;
&amp;lt; choice value=" | eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?&amp;amp;lt;time_offset_seconds&amp;amp;gt;\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" | &amp;gt;TZ&amp;lt; /choice&amp;gt; &amp;lt; /input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:51:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301234#M90703</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-07T13:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301235#M90704</link>
      <description>&lt;P&gt;&lt;STRONG&gt;EventHandler.setToken("tzadjust", "| eval time_splunk=strftime(_time, \"%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)\") | eval time_offset=strftime(_time, \"%:z\") | rex field=time_offset \".(?\d{2}:\d{2})\" | eval time_offset_seconds=time_offset_seconds.\":00\" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, \"%s\") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)==\"+\", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , \"%Y-%m-%d %H:%M:%S\") | eval _time = strptime(time_utc,\"%Y-%m-%d %H:%M:%S\")  ", {}, e.data);&lt;BR /&gt;
}&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;This is how I set my token and I have to escape \d in the rex field portion.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:48:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301235#M90704</guid>
      <dc:creator>waltz</dc:creator>
      <dc:date>2020-09-29T14:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301236#M90705</link>
      <description>&lt;P&gt;can you try updated query (replacing &lt;CODE&gt;&amp;lt;&lt;/CODE&gt; and &lt;CODE&gt;&amp;gt;&lt;/CODE&gt; with corresponding html code.)&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 14:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301236#M90705</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-07T14:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301237#M90706</link>
      <description>&lt;P&gt;The query which I had provided earlier was a dummy one &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt; . This is the actual one :&lt;/P&gt;

&lt;P&gt;| eval time_splunk=strftime(_time, "%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)")  | eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, "%s") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)=="+", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , "%Y-%m-%d %H:%M:%S") | eval _time = strptime(time_utc,"%Y-%m-%d %H:%M:%S") &lt;/P&gt;

&lt;P&gt;I need the modifed token of the corresponding html code .&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:48:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301237#M90706</guid>
      <dc:creator>waltz</dc:creator>
      <dc:date>2020-09-29T14:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301238#M90707</link>
      <description>&lt;P&gt;Try with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval time_splunk=strftime(_time, "%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)") | eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?&amp;amp;lt;time_offset_seconds&amp;amp;gt;\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, "%s") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)=="+", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , "%Y-%m-%d %H:%M:%S") | eval _time = strptime(time_utc,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jul 2017 14:36:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301238#M90707</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-07T14:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I escape backslash in a token to modify a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301239#M90708</link>
      <description>&lt;P&gt;Enclose the entire search string in a CDATA tag, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt; input type="dropdown" token="tzz" searchWhenChanged="true"&amp;gt;
   &amp;lt; choice value="![CDATA[| eval time_splunk=strftime(_time, "%A, %B %e, %Y %l:%M:%S.%3Q %p %Z (%:z)")  | eval time_offset=strftime(_time, "%:z") | rex field=time_offset ".(?&amp;lt;time_offset_seconds&amp;gt;\d{2}:\d{2})" | eval time_offset_seconds=time_offset_seconds.":00" | convert dur2sec(time_offset_seconds) | eval time_utc_epoch=strftime(_time, "%s") | convert num(time_utc_epoch) | eval time_utc_epoch=if(time_offset_seconds==0, time_utc_epoch, if(substr(time_offset, 1, 1)=="+", time_utc_epoch-time_offset_seconds, time_utc_epoch+time_offset_seconds)) | eval time_utc=strftime(time_utc_epoch , "%Y-%m-%d %H:%M:%S") | eval _time = strptime(time_utc,"%Y-%m-%d %H:%M:%S") ", {}, e.data); }]]&amp;gt;TZ&amp;lt; /choice&amp;gt;
&amp;lt; /input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Jul 2017 18:33:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-escape-backslash-in-a-token-to-modify-a-search/m-p/301239#M90708</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-08T18:33:09Z</dc:date>
    </item>
  </channel>
</rss>

