Hello community of StackOverflow, I commented that you have to validate a string entered from the keyboard that should only contain the letters a and b and have at least one space. With the code I have so far there is no problem with chains of type "abbaab abba", the problem is that it also validates the strings that do not have space, what do I have to add so that it no longer validates the strings that do not have space? '
Scanner entrada = new Scanner(System.in);
String cadena = entrada.nextLine();
Pattern rango = Pattern.compile("[^A-Ba-b ]");
Matcher cadenaValida = rango.matcher(cadena);
if (!cadenaValida.find())
System.out.println("La cadena que ingresaste es valida");
else
System.out.println("La cadena no es valida");