ksm*_*001 3 java regex string replaceall
String foo = "a3#4#b";
String afterPunctutationRemoval = foo.replaceAll("[,.;:?!'-_\"/()\\{}]", "");
System.out.println(afterPunctutationRemoval);
Run Code Online (Sandbox Code Playgroud)
它给了我一个"## b"的结果,有人可以解释我为什么吗?
它不应该按原样返回字符串吗?
Bar*_*ers 11
您的角色类包含与数字匹配的范围'.._
把它放在-角色类的开头或结尾:
foo.replaceAll("[,.;:?!'_\"/()\\{}-]", "")
Run Code Online (Sandbox Code Playgroud)
或逃避它:
foo.replaceAll("[,.;:?!'\\-_\"/()\\{}]", "");
Run Code Online (Sandbox Code Playgroud)