You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
403 B
JavaScript

'use strict';
module.exports = function extractGarbage(body) {
let snippetRegex = /(^|[^\n]+\n)([0-9a-f]+)(\s*)($|\n[^\n]+)/g;
let snippets = [];
let match;
while (match = snippetRegex.exec(body)) {
snippets.push({before: match[1], garbage: match[2], whitespace: match[3], after: match[4]});
snippetRegex.lastIndex -= match[4].length; // To allow overlapping matches
}
return snippets;
};