const regex = new RegExp('^(.*?)/(.*?),now\\s(.*?)\\s(.*?)\\s', 'g')
const str = `usbmuxd/kali-rolling,now 1.1.0-2+b1 amd64 [installed,automatic]
usbutils/kali-rolling,now 1:007-4 amd64 [installed]
util-linux/kali-rolling,now 2.28-6 amd64 [installed]
uuid-runtime/kali-rolling,now 2.28-6 amd64 [installed,automatic]
va-driver-all/kali-rolling,now 1.7.1-2 amd64 [installed,automatic]
vboot-kernel-utils/kali-rolling,now 0~R52-8350.B-1 amd64 [installed,automatic]
vboot-utils/kali-rolling,now 0~R52-8350.B-1 amd64 [installed,automatic]
vdpau-driver-all/kali-rolling,now 1.1.1-3 amd64 [installed,automatic]
`;
// 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