const regex = /(^\w+\s?\D+)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(^\\w+\\s?\\D+)\\s?(\\d+[,\\d+]*)\\s?(\\d+[,\\d+]*)\\s?(\\d+[,\\d+]*)\\s?(\\d+[,\\d+]*)\\s?(\\d+[,\\d+]*)\\s?', 'gmi')
const str = `Weapon Type/Force Used 2000 2001 2002 2003 2004 5-Year Total
Personal Weapons 12,945 17,830 20,636 21,933 25,050 98,394
None 2,702 3,114 2,974 3,294 4,176 16,260
Other 1,775 2,311 2,332 2,420 2,842 11,680
Knife/Cutting Instrument 1,511 2,082 2,080 2,445 2,852 10,970
Handgun 307 376 398 430 497 2,008
Blunt Object 283 404 394 455 469 2,005
Firearm (type not stated) 94 131 103 135 146 609
Other Firearm 74 107 92 155 154 582
Explosives 145 139 93 89 95 561
Motor Vehicle 43 52 46 59 71 271
Fire/Incendiary Device 36 34 42 36 88 236
Rifle 23 33 33 24 37 150
Shotgun 15 24 30 19 24 112
Drugs/Narcotics/Sleeping Pills 9 4 8 14 6 41
Poison 1 8 4 11 16 40
Asphyxiation 2 1 3 6 2 14
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions