title: What's the best/fastest way to find the number of tabs to start a string?
body: <p>I want to find the number of tabs at the beginning of a string (and of course I want it to be fast running code ;) ). This is my idea, but not sure if this is the best/fastest choice:</p>
  
  <pre><code>//The regular expression
  var findBegTabs = /(^\t+)/g;
  
  //This string has 3 tabs and 2 spaces: "&lt;tab&gt;&lt;tab&gt;&lt;space&gt;something&lt;space&gt;&lt;tab&gt;"
  var str = "      something  ";
  
  //Look for the tabs at the beginning
  var match = reg.exec( str );
  
  //We found...
  var numOfTabs = ( match ) ? match[ 0 ].length : 0;
  </code></pre>
  
  <p>Another possibility is to use a loop and charAt:</p>
  
  <pre><code>//This string has 3 tabs and 2 spaces: "&lt;tab&gt;&lt;tab&gt;&lt;space&gt;something&lt;space&gt;&lt;tab&gt;"
  var str = "      something  ";
  
  var numOfTabs = 0;
  var start = 0;
  
  //Loop and count number of tabs at beg
  while ( str.charAt( start++ ) == "\t" ) numOfTabs++;
  </code></pre>