我需要找到所有特殊字符,甚至是sting中的空格,并将其作为输出打印出来..
我尝试了以下内容.
public class SpecialChar {
public static void main(String[] args) {
String s = "adad , dsd r dsdsd,,,,..////";
for (int i = 0; i < s.length(); i++)
{
System.out.println(s.charAt(i));
}
System.out.println("i");
String REGEX = "[^&%$#@!~ ,]*";
Pattern pattern = Pattern.compile(REGEX);
Matcher matcher = pattern.matcher(i);
if (matcher.matches()) {
System.out.println("matched");
}
}
}
Run Code Online (Sandbox Code Playgroud)