Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using String.matches("\\S") does not work with more than one character

800348Aug 15 2008 — edited Aug 15 2008
This is a rather simple question,

Why is it that doing

System.out.print("b".matches("\\S")); produces true

and

System.out.print("ba".matches("\\S")); produces false?

using \S should return true if there are any non whitespace characters in the string but why is the result affected by how many characters are in the string?

I just want to check if a string (of any length) contains non whitespace characters.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 12 2008
Added on Aug 15 2008
12 comments
1,435 views