const regex = new RegExp('(?:\\d+\\s+)(\\w+)(?:\\s+)(\\w+)', 'gm')
const str = ` Id Name State
----------------------------------------------------
14 vm2 running
19 vm7 running
22 vm10 running
27 vm11 running
36 vm9 running
38 vm12 running
43 vm6 running
46 vm1 running
49 vm4 running
63 vm5 running
65 vm8 running
67 vm3 running
`;
// 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