Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal octal escape sequence near index 2
\0
^
at java.util.regex.Pattern.error(Pattern.java:1924)
at java.util.regex.Pattern.o(Pattern.java:3139)
at java.util.regex.Pattern.escape(Pattern.java:2266)
at java.util.regex.Pattern.atom(Pattern.java:2164)
at java.util.regex.Pattern.sequence(Pattern.java:2046)
at java.util.regex.Pattern.expr(Pattern.java:1964)
at java.util.regex.Pattern.compile(Pattern.java:1665)
at java.util.regex.Pattern.<init>(Pattern.java:1337)
at java.util.regex.Pattern.compile(Pattern.java:1022)
at java.lang.String.replaceAll(String.java:2162)
at est.Test.main(Test.java:12)
#4
package est;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s= "12341234\0ddd12348979xasfasdf";
int y =s.length();
int x= s.indexOf("\n");
String s1= s.replaceAll("\n", "").replaceAll(" ", "");
String s2=s.replaceAll("\0", "");
String s3=s.replaceAll("\\0", "");
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal octal escape sequence near index 2
\0
^
at java.util.regex.Pattern.error(Pattern.java:1924)
at java.util.regex.Pattern.o(Pattern.java:3139)
at java.util.regex.Pattern.escape(Pattern.java:2266)
at java.util.regex.Pattern.atom(Pattern.java:2164)
at java.util.regex.Pattern.sequence(Pattern.java:2046)
at java.util.regex.Pattern.expr(Pattern.java:1964)
at java.util.regex.Pattern.compile(Pattern.java:1665)
at java.util.regex.Pattern.<init>(Pattern.java:1337)
at java.util.regex.Pattern.compile(Pattern.java:1022)
at java.lang.String.replaceAll(String.java:2162)
at est.Test.main(Test.java:12)
#4
"原文本".replaceAll("\\0", "");
package est;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s= "12341234\0ddd12348979xasfasdf";
int y =s.length();
int x= s.indexOf("\n");
String s1= s.replaceAll("\n", "").replaceAll(" ", "");
String s2=s.replaceAll("\0", "");
String s3=s.replaceAll("\\0", "");
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);