I\'m trying the username chains in Java with following rules:
BTW, if there is an extra requirement: the starting letter of the username must be a character, you can write
try {
if (subjectString.matches("\\b[a-zA-Z][a-zA-Z0-9\\-._]{3,}\\b")) {
// Successful match
} else {
// No match
}
} catch (PatternSyntaxException ex) {
// Invalid regex
}
Based on an example here.