0

This string contains spaces followed by DOT(.) and then some character. Then why regex is returning false?

String s="               .fds";
System.out.println(Pattern.matches("\\S+", s));
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 2
    Because `matches` requires a full string match, and `\\S+` does not match leading spaces. – Wiktor Stribiżew Aug 24 '16 at 07:10
  • There are 2 things that are wrong, first of, the whitespace is a lowercase s as `\\s`. And as @WiktorStribiżew already said, `Pattern#matches` does a full `String` match, so you´d have to modify your regex in some way that the `.fds` would also be included in there. – SomeJavaGuy Aug 24 '16 at 07:12

0 Answers0