const regex = /^((([0-9]{3}(?![0-9]))|([a-z]{3}(?![a-z])))|(([0-9]{1,2})|([a-z]{1,2}))|-){6,}/gim;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^((([0-9]{3}(?![0-9]))|([a-z]{3}(?![a-z])))|(([0-9]{1,2})|([a-z]{1,2}))|-){6,}', 'gim')
const str = `1234as
12as32
09ppdj
ppdj09
12asd3
er123a
123ab2
2dgs23
123as2
asd12a
p23bgf
asdfdw
123432
123asd
ds321a
12asd1
1234aa
a321as
3asr33
V-127-DR 27-09-2017 t/m 26-10-2017 MEER INFO WWW.BELASTINGDIENST.NL
XX-99-99- asda sda
99-99-XX boekeing asdasdasd
99-XX-99 achrijving
XX-99-XX
deze matcht niet XX-XX-99 want het begint niet met een kenteken
99-XX-XX
99-XXX-9
9-XXX-99 dit is een omgschrijving van de belastingdienst
XX-999-X
X-999-XX
XXX-99-X`;
// 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