const regex = /(\d{1}\.\d{5,8}|0)\s/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\d{1}\\.\\d{5,8}|0)\\s', 'gm')
const str = `0.1766155 0.1658146 0.3464225 0.258326 1.040629 0.3123467 0.7877846 0.1264636 0.1854926 2.235324 0 0.3128409 0.5384811 0.2159374 0.1659985 0.2901815 0.08226276 0.1323811 0.1374549 0.04583898 0.1653796 0.02095086 0.1465107 `;
// 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