const regex = /^(?'Vmid'\d+)(\s+)((?'Name'\S.+\S)?)(\s+)(?'Datastore'\[\S+\])(\s+)(?'File'.+\.vmx)(\s+)(?'GuestOS'\S+)(\s+)(?'Version'vmx-\d+)(\s*?)((?'Annotation'\S.+)?)$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?\'Vmid\'\\d+)(\\s+)((?\'Name\'\\S.+\\S)?)(\\s+)(?\'Datastore\'\\[\\S+\\])(\\s+)(?\'File\'.+\\.vmx)(\\s+)(?\'GuestOS\'\\S+)(\\s+)(?\'Version\'vmx-\\d+)(\\s*?)((?\'Annotation\'\\S.+)?)$', 'gm')
const str = `Vmid Name File Guest OS Version Annotation
10 X9SRI-3F-W10P-EN-MEDIA [EVO860_500GB] VM/X9SRI-3F-W10P-EN-MEDIA/X9SRI-3F-W10P-EN-MEDIA.vmx windows9_64Guest vmx-14
5 PPB Local_Virtual Machine_v4.0 [EVO860_500GB] VM/PPB-Local_Virtual-Machine_v4.0/PPB Local_Virtual Machine_v4.0.vmx centos64Guest vmx-11 PowerPanel Business software(Local) provides the service which communicates
with the UPS through USB or Serial cable and relays the UPS state to each Remote on other computers
via a network.
It also monitors and logs the UPS status. The computer which has been installed the Local provides
graceful,
unattended shutdown in the event of the power outage to protect the hosted computer.
15 X9SRI [-] 3F-W10P-EN-MEDIA [EVO860_500GB] VM/X9SRI-3F-W10P-EN-MEDIA/X9SRI-3F-W10P-EN-MEDIA.vmx windows9_64Guest vmx-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