I'm trying to match cases where a sequence of characters contains three or more identical characters in any position, as shown in the following code:
class TRY {
public static void main(String[] args) {
String a = "aaaam";
String b = "aacccccccc";
String c = "aaffffkb";
if (b.matches("([a-zA-Z0-9])\\1+"))
System.out.println("Matches!"); // Display the string.
}
}
There are many other questions online that suggest using a regular expression like ([a-zA-Z0-9])\\1+ ; "([a-z\\d])\\1{3,}" ; or "([a-z\\d])\\1\\1". The [a-zA-Z0-9] should match any character, and the \\1 should reference the matched character. However none of these match any of my strings, and I don't understand why.