我需要检查一个字符串是否包含空格、逗号和多个@ 符号。我使用了以下方法来这样做,但它对我来说效果不佳。
boolean flag = string.matches("\\s,@");
你们中的任何人都可以告诉我它出了什么问题吗?
最佳答案
试试这个
Pattern pattern = Pattern.compile("[,\\s]|@.*@");
Matcher m = pattern.matcher(your_string);
boolean b = m.find();
关于java - 检查一个字符串是否包含空格和多个@符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9683238/