title: Snowflake removing backslashes during Procedure compilation?
body: <p>For some reason Snowflake is removing backslashes from my regex function, but only when I put the function in between the &quot;$$&quot; when creating a Javascript procedure.</p>
  <p>For context here is my Regex Function:</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION &quot;REGEX_REPLACE_ME&quot;(&quot;SUBJECT&quot; VARCHAR(16777216), &quot;PATTERN&quot; VARCHAR(16777216), &quot;REPLACEMENT&quot; VARCHAR(16777216))
  RETURNS VARCHAR(16777216)
  LANGUAGE JAVASCRIPT
  AS '
    
      const p = SUBJECT;
      let regex = new RegExp(PATTERN, ''i'') 
      return p.replace(regex, REPLACEMENT);
    ';
  </code></pre>
  <p>When I run it simply in SQL, it works; it will change &quot;APPLE.com&quot; to &quot;APPLE&quot;.</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT REXP_REPLACE_ME('APPLE.COM','\\.[A-Z]{2,3}',' ') -- the regex pattern \\.[A-Z]{2,3} is meant to remove domains i.e. &quot;.com&quot;,&quot;.org&quot;, etc.. 
  </code></pre>
  <p>However, when I run it within $$ of a stored procedure, it removes the backslashes from my regex pattern and consequently changing the regex pattern completely.</p>
  <p>My regex changes from <code>\\.[A-Z]{2,3}</code> to -&gt;  <code>.[A-Z]{2,3}</code></p>
  <pre class="lang-sql prettyprint-override"><code>CREATE or replace PROCEDURE TESTING_FUNC_1_THIS_CAN_BE_DELETED()
  RETURNS VARCHAR
  LANGUAGE javascript
  AS
  $$
  
  var rs = snowflake.execute( { sqlText:
  `
      CREATE OR REPLACE VIEW Database.Schema.Table AS
  
      SELECT REXP_REPLACE_ME('APPLE.COM','\\.[A-Z]{2,3}',' ')  as column_cleaned
   --   ,REXP_REPLACE_ME_WTF('APPLE.COM','\\.[A-Z]{2,3}',' ') AS WHAT_PATTERN_IS_BEING_OUTPUTTED -- function logic in code block below
      
  `
                              } );
    $$;
  
  call TESTING_FUNC_1_THIS_CAN_BE_DELETED();
  
  select * from Database.Schema.Table
  </code></pre>
  <p>Scratching my head here, I created this function to show what pattern it was outputting and this is how I came to the conclusion (I can be wrong here..) that when Snowflake is compiling it's removing the backslash...</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION &quot;REXP_REPLACE_ME_WTF&quot;(&quot;SUBJECT&quot; VARCHAR(16777216), &quot;PATTERN&quot; VARCHAR(16777216), &quot;REPLACEMENT&quot; VARCHAR(16777216))
  RETURNS VARCHAR(16777216)
  LANGUAGE JAVASCRIPT
  AS '
    
      const p = SUBJECT;
      let regex = new RegExp(PATTERN, ''i'');
      //return p.replace(regex, REPLACEMENT);
      return PATTERN;
    ';
  </code></pre>
  <p>Any ideas?</p>