const regex = /^(?=.*\d)[\D\S]\S{5,17}(\S)\1$/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?=.*\\d)[\\D\\S]\\S{5,17}(\\S)\\1$', 'gmi')
const str = `+234567899
a_1de*Gg
xy1Me*__
!41deF_hij2lMnopq3ss
C234567890123\$^67800
*5555555
sDF564zer""
!!!!!!!!!4!!!!!!!!!!
abcdefghijklmnopq9ss
a_1+Eff
B41def_hIJ2lmnopq3stt
abCDefghijklmnopqrss5
A_4 e*gg
__1+Eff
841DEf_hij2lmnopq3stt
a_1+eFg
b41DEf_hij2lmnopq3st
abCDefghijklmnopqrss
abcdef+++dF
!!!!!!!!!!!!!!!!!!!!`;
// 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