code: function findTag(re,s)
      {
          var openCount = 0;
          var offset = 0;
          var ldelim = jSmart.prototype.left_delimiter;
          var rdelim = jSmart.prototype.right_delimiter;
          var skipInWS = jSmart.prototype.auto_literal;
  
          var reTag = new RegExp('^\\s*('+re+')\\s*$','i');
  
          for (var i=0; i<s.length; ++i)
          {
              if (s.substr(i,ldelim.length) == ldelim)
              {
                  if (skipInWS && i+1 < s.length && s.substr(i+1,1).match(/\s/))
                  {
                      continue;
                  }
                  if (!openCount)
                  {
                      s = s.slice(i);
                      offset += i;
                      i = 0;
                  }
                  ++openCount;
              }
              else if (s.substr(i,rdelim.length) == rdelim)
              {
                  if (skipInWS && i-1 >= 0 && s.substr(i-1,1).match(/\s/))
                  {
                      continue;
                  }
                  if (!--openCount)
                  {
                      var sTag = s.slice(ldelim.length,i).replace(/[\r\n]/g, ' ');
                      var found = sTag.match(reTag);
                      if (found)
                      {
                          found[0] = s.slice(0,i+rdelim.length);
                          found.index = offset;
                          return found;
                      }
                  }
                  if (openCount < 0) //ignore unmatched right delimiter
                  {
                      openCount = 0;
                  }
              }
          }
          return null;
      }
docs: finds first {tag} in string
  @param re string with regular expression
  @return  null or s.match(re) result object where
  [0] - full tag matched with delimiters (and whitespaces at the begin and the end): { tag }
  [1] - found part from passed re
  [index] - position of tag starting { in s