const regex = /graphiceq\s*:((?:\s*\d++(?:,\d++)?+(?:\.\d++)?+\s++[+-]?+\d++(?:\.\d++)?+[ \t]*+(?:;|$))++)/gim;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('graphiceq\\s*:((?:\\s*\\d++(?:,\\d++)?+(?:\\.\\d++)?+\\s++[+-]?+\\d++(?:\\.\\d++)?+[ \\t]*+(?:;|$))++)', 'gim')
const str = `# A 15-band graphic equalizer with ISO bands
GraphicEQ: 25 6; 40 4.5; 63 3; 100 1.5; 160 0; 250 0; 400 0; 630 0; 1000 0; 1600 0; 2500 0; 4000 0; 6300 1.5; 10,000 +3; 16,000 +3
# A custom graphic equalizer
GraphicEQ: 20.00 0.00; 25.00 -1.75; 30.00 -3.20; 35.00 -4.15; 40.00 -4.90; 45.00 -5.55; 50.00 -6.10; 60.00 -6.90; 70.00 -7.40; 80.00 -7.80; 90.00 -8.10; 100.00 -8.30
The regex used is more permissive than the original specification (https://sourceforge.net/p/equalizerapo/wiki/Configuration%20reference/#graphiceq-since-version-10):
- Gain value can be signed (+/-);
- Frequency can use a comma as thousand separator
The last class does not include the newline as whitespaces to allow matching the \`\$\` as the end of line (multiline flag is used).`;
// 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