title: Uncaught TypeError: Cannot read property 'toString' of null
body: <p>I have this message: "Uncaught TypeError: Cannot read property 'toString' of null" while running the code below. Any help would be appreciated since I am not familiar with Javascript </p>
  
  <p>Thank you in advance.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getUrlVars() {
      var arrGamePath = document.referrer;
      if(arrGamePath) {
          var reg = new RegExp("[/][a-zA-Z]{2}-[a-zA-Z]{2,4}[/]");
          var locale = reg.exec(arrGamePath) .toString();
          while (locale.indexOf("/") != -1) {
              locale = locale.replace("/", "");
          }
          return locale;
      }else{
          return false;
      }
  }
  
  if(getUrlVars()) {
      sCID = getUrlVars();
  }</code></pre>
  </div>
  </div>
  </p>