<?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 Regex: Error using where/match and backslash character in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-Error-using-where-match-and-backslash-character/m-p/551153#M156393</link>
    <description>&lt;P&gt;The following example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval FilePath="\\Temp.exe"
| where match(FilePath, "(?i)\\Temp\.exe$")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Creates a field FilePath with the value \Temp.exe&lt;/P&gt;&lt;P&gt;So, to match that, I am escaping the single slash with 2 slashes in the match statement, but that gives the error&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Error in 'where' command: Regex: unrecognized character follows \&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If I use \\s then the search does not fail with an error, presumably because \s is a valid character class expression, whereas \T is not.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, based on the description of the eval/replace function&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.3/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/8.1.3/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if I double escape the \, so use&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval FilePath="\\Temp.exe"
| where match(FilePath, "(?i)\\\\Temp\.exe$")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then it works, so I was looking to clarify that this is due to the same double escaping requirement ONLY for the \ character and if so, is this a general that PCRE expressions inside eval statements, that have \, will always need the 4* instance of the \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 May 2021 03:59:49 GMT</pubDate>
    <dc:creator>abowesman</dc:creator>
    <dc:date>2021-05-11T03:59:49Z</dc:date>
    <item>
      <title>Regex: Error using where/match and backslash character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Error-using-where-match-and-backslash-character/m-p/551153#M156393</link>
      <description>&lt;P&gt;The following example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval FilePath="\\Temp.exe"
| where match(FilePath, "(?i)\\Temp\.exe$")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Creates a field FilePath with the value \Temp.exe&lt;/P&gt;&lt;P&gt;So, to match that, I am escaping the single slash with 2 slashes in the match statement, but that gives the error&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Error in 'where' command: Regex: unrecognized character follows \&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If I use \\s then the search does not fail with an error, presumably because \s is a valid character class expression, whereas \T is not.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, based on the description of the eval/replace function&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.3/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/8.1.3/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if I double escape the \, so use&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval FilePath="\\Temp.exe"
| where match(FilePath, "(?i)\\\\Temp\.exe$")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then it works, so I was looking to clarify that this is due to the same double escaping requirement ONLY for the \ character and if so, is this a general that PCRE expressions inside eval statements, that have \, will always need the 4* instance of the \&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 03:59:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Error-using-where-match-and-backslash-character/m-p/551153#M156393</guid>
      <dc:creator>abowesman</dc:creator>
      <dc:date>2021-05-11T03:59:49Z</dc:date>
    </item>
  </channel>
</rss>

