I'm not quite sure, what we might wish to pass and fail, however based on your original expression my guess is that this might be what we might want to start with with an i
flag:
^[A-Z ]{3,}-\d{1,6}$
or without i
flag:
^[A-Za-z ]{3,}-\d{1,6}$
Test
const regex = /^[A-Z ]{3,}-\d{1,6}$/gmi;
const str = `Some Text-1
Some Text-201901
Some Text-20190101`;
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}`);
});
}
RegEx
If this expression wasn't desired, it can be modified/changed in regex101.com.
RegEx Circuit
jex.im visualizes regular expressions:
