Matching non spaces in Java

I want to detect strings that contain non white space characters Now I'm trying:

!Pattern.matches("\\*\\S\\*",city)

But it doesn't seem to work Does anyone have any suggestions? I know I can trim a string and test whether it is equal to an empty string, but I'd rather do so

Solution

What do you think regular expressions match?

attempt

Pattern p = Pattern.compile( "\\S" );
Matcher m = p.matcher( city );
if( m.find() )
//contains non whitespace

The find method will search for partial matches, not exact matches This seems to be the behavior you need

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>