const regex = /(?x) #ignora isso é para aceitar multi linha e comentario
^ # inicio
(?=.*?[a-z]) # procura por caracteres `a` atá `z` pelo menos 1
(?=(?:.*?\d){9}) # procura por 9 digitos
[a-z\d ]{12,} # tem que ter 12 digitos ou mais entre `a` e `z` numeros e espaços
$ # fim
/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?x) #ignora isso é para aceitar multi linha e comentario
^ # inicio
(?=.*?[a-z]) # procura por caracteres `a` atá `z` pelo menos 1
(?=(?:.*?\\d){9}) # procura por 9 digitos
[a-z\\d ]{12,} # tem que ter 12 digitos ou mais entre `a` e `z` numeros e espaços
$ # fim
', 'gmi')
const str = `aeioa123rasdaer12311412s
a 1 2 3 4 a f e 4 6 9 a 1 2
falha Por Que so tem Letras e espaço
012345679PassaPorqueTemNumeros
444Pass4 3P0r que T3m L3tr4as numeros e espaco
012345678901`;
// 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