const regex = /$(?<!_1[6-9]|_2[0-4])/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('$(?<!_1[6-9]|_2[0-4])', 'gm')
const str = `x2016_17_7
x2017_188
x2018_199
x2019_20_10
x2020_21_11
x2021_22_12
x2022_23_13
x2023_20_10
x202025_15
x2016_17_16
x2017_18_17
x2018_19_18
x2019_20_19
x2020_21_20
x2021_22_21
x2022_23_22
x2023_20_23
x2020_25_20`;
// 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