const regex = new RegExp('^(?P<reducer>\\w+)\\(\\)\\s+of\\s+query\\((?P<dashboardUID>\\w+)\\/(?P<panelID>\\d+)\\/(?P<metric>.+),\\s+(?P<from>\\w+),\\s+(?P<to>\\w+)\\)\\s+is\\s+(?P<evaluator>\\w+)\\((?P<params>-*\\d*[\\.,\\s]*\\d*\\w*)\\)\\s*(for\\s+\\((?P<for>\\w+)\\))*\\s*(every\\((?P<every>\\w+)\\))*\\s*$', 'gm')
const str = `avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is below(14)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is below(0.4)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is novalue()
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88) for (1m)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88) for (1m) every(1m)
avg() of query(summary/152/tx-avg, 1m, now) is below(5000)
avg() of query(summary/152/tx-avg, 1m, now) is below(-5000)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is above(300M)`;
// 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