const regex = /(\w*\(Hex\): w*)(.*?)(?= |$)/gmsi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\w*\\(Hex\\): w*)(.*?)(?= |$)', 'gmsi')
const str = ` Vserver Name: vs1
LUN Path: /vol/vol1/lun1
Volume Name: vol1
Qtree Name: ""
LUN Name: lun1
LUN Size: 10MB
OS Type: linux
Space Reservation: disabled
Serial Number: wCVt1]IlvQWv
Serial Number (Hex): 77435674315d496c76515776
Comment: new comment
Space Reservations Honored: false
Space Allocation: disabled
State: offline
LUN UUID: 76d2eba4-dd3f-494c-ad63-1995c1574753
Mapped: mapped
Block Size: 512
Device Legacy ID: -
Device Binary ID: -
Device Text ID: -
Read Only: false
Fenced Due to Restore: false
Used Size: 5MB
Maximum Resize Size: 64.00GB
Creation Time: 9/14/2016 13:55:09
Class: regular
Node Hosting the LUN: node1
QoS Policy Group: -
Caching Policy Name: -
Clone: false
Clone Autodelete Enabled: false
Inconsistent Import: false
Application: -`;
// 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