UNPKG

regex-occurrence

Version:

Get the number of occurrences of a RegExp in a string

11 lines (9 loc) 275 B
'use strict'; module.exports = function (input, search) { if (typeof input !== 'string') { throw new TypeError('The input should be a string'); } return [].concat(search).reduce(function (count, search) { return count + (input.match(search) || []).length; }, 0); };