const regex = /^(.{20})[^.]{4,}(.*)$/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(.{20})[^.]{4,}(.*)$', 'gmi')
const str = `1.1234567890.ab
2.123456789012345678901.ab
3.1234567890123456789012.ab
4.12345678901234567890123.ab
5.123456789012345678901234.ab
6.1234567890123456789012345.ab
7.12345678901234567890123456.ab
8.123456789012345678901234567890.ab
9.123456789012345678901234567890.1234567890123456.7890.ab
0.123456789012345678901234567890.12345678901.234567890....abcdef012345
12345678901234567890123456789012345678901234567890`;
// 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