const regex = new RegExp('(?m)^NAME="(?P<name>(?P<disk>[a-z]+)(?P<partition>\\d*))"\\sFSTYPE="(?P<fstype>\\w*)"\\sMOUNTPOINT="(?P<mountpoint>[\\w\\[\\]/]*)"\\sSIZE="(?P<size>\\d*)"\\sTYPE="(?P<type>\\w+)"$', 'gm')
const str = `NAME="loop0" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="20971520000" TYPE="loop"
NAME="sda" FSTYPE="" MOUNTPOINT="" SIZE="171798691840" TYPE="disk"
NAME="sda1" FSTYPE="ext4" MOUNTPOINT="/boot" SIZE="1073741824" TYPE="part"
NAME="sda2" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="170723901440" TYPE="part"
NAME="sdb" FSTYPE="" MOUNTPOINT="" SIZE="32212254720" TYPE="disk"
NAME="sdb1" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="32211206144" TYPE="part"
NAME="sdc" FSTYPE="" MOUNTPOINT="" SIZE="53687091200" TYPE="disk"
NAME="sdc1" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="53686042624" TYPE="part"
NAME="sr0" FSTYPE="" MOUNTPOINT="" SIZE="1073741312" TYPE="rom"
NAME="cl_ctos8auto-root" FSTYPE="xfs" MOUNTPOINT="/" SIZE="106300440576" TYPE="lvm"
NAME="cl_ctos8auto-root" FSTYPE="xfs" MOUNTPOINT="/" SIZE="106300440576" TYPE="lvm"
NAME="cl_ctos8auto-swap" FSTYPE="swap" MOUNTPOINT="[SWAP]" SIZE="8497659904" TYPE="lvm"
NAME="cl_ctos8auto-home" FSTYPE="xfs" MOUNTPOINT="/home" SIZE="108536004608" TYPE="lvm"
NAME="cl_ctos8auto-var_log" FSTYPE="ext4" MOUNTPOINT="/opt/imsdb/chroot-sybase/var/log" SIZE="32208060416" TYPE="lvm"
NAME="b38ad718--fc07--11ea--9894--0050569ae644-fea1a18c--fc07--11ea--9894--0050569ae644" FSTYPE="ext4" MOUNTPOINT="/opt/intelerad/atlas/1/storage/b30f29df-8fc2-4db5-8c17-4275cdae6b3f" SIZE="20967325696" TYPE="lvm"`;
// 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