const regex = /^(.*?) : (.+? MB\/s)( \[.*)?$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(.*?) : (.+? MB\\\/s)( \\[.*)?$', 'gm')
const str = `Sequential Read : 135.091 MB/s
Sequential Write : 126.046 MB/s
Random Read 512KB : 44.569 MB/s
Random Write 512KB : 117.965 MB/s
Random Read 4KB (QD=1) : 0.468 MB/s [ 114.4 IOPS]
Random Write 4KB (QD=1) : 8.412 MB/s [ 2053.6 IOPS]
Random Read 4KB (QD=32) : 0.654 MB/s [ 159.6 IOPS]
Random Write 4KB (QD=32) : 10.751 MB/s [ 2624.7 IOPS]
Test : 1000 MB [C: 7.3% (64.9/889.4 GB)] (x5)
Date : 2015/12/09 22:06:02
OS : Windows 8.1 [6.3 Build 9600] (x64)`;
// 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