title: JavaScript date/time pattern %t{yyyyMMdd-HHmm} - RegExp to read pattern
body: <p>Below is Node.js module with function <code>format()</code> that is actually taken from Node.js 'util' module <a href="http://www.nodejs.org/api/util.html#util_util_format_format" rel="nofollow"><code>util.format(format, [...])</code></a></p>
  
  <p>date.js adds format() function to Date prototype.</p>
  
  <p>How to make RegExpression so that it can extract time format pattern after the placeholder?</p>
  
  <pre><code>// from Node.js util module
  util = require ('util');
  inspect = util.inspect;
  require('./date.js'); // adds .format to Date prototype
  
  var formatRegExp = /%[sdjt%]/g; //+ t
  exports.format = function(f) {
    if (typeof f !== 'string') {
      var objects = [];
      for (var i = 0; i &lt; arguments.length; i++) {
        objects.push(inspect(arguments[i]));
      }
      return objects.join(' ');
    }
  
    var i = 1;
    var args = arguments;
    var len = args.length;
    var str = String(f).replace(formatRegExp, function(x) {
      if (x === '%%') return '%';
      if (i &gt;= len) return x;
      switch (x) {
        case '%s': return String(args[i++]);
        case '%d': return Number(args[i++]);
        case '%j': return JSON.stringify(args[i++]);
        // added time = new Date().format('yyyy-MM-dd H:m:s');
        case '%t': return args[i++].format('yyyy-MM-dd HH:mm:ss'); //+ added line
        default:
          return x;
      }
    });
    for (var x = args[i]; i &lt; len; x = args[++i]) {
      if (x === null || typeof x !== 'object') {
        str += ' ' + x;
      } else {
        str += ' ' + inspect(x);
      }
    }
    return str;
  };
  </code></pre>
  
  <p>Maybe there is other solution to support exact format usage with <code>%t{yyyyMMdd-HHmm}</code> </p>
  
  <p><code>console.log( formatutil.format('log-%t{yyyyMMdd-HHmm}.log', curtime ) );</code></p>
  
  <p>UPDATE:</p>
  
  <p><strong>that is what RegExp could catch '%t{yyyyMMdd-HHmm}' in 'log-%t{yyyyMMdd-HHmm}.log'</strong></p>