'use strict'; function create(tokens) { function getToken(matches) { for (var i=0; i { return '(' + token.pattern.source + ')'; }) .join('|'), 'g'); return { forEachToken: function(value, callback, thisObj) { tokensRegExp.lastIndex = 0; // Start searching from the beginning again var matches; while ((matches = tokensRegExp.exec(value))) { let token = getToken(matches); callback.call(this, token); } } }; } exports.create = create;