java匹配竖线的错误警示
程序员文章站
2022-04-28 13:37:33
``` String s1 = "|"; // 输出 | System.out.println(s1); String s2 = s1.replaceAll("|","1"); // 输出 1|1 System.out.println(s2); String s3 = ""; String s4 =... ......
string s1 = "|"; // 输出 | system.out.println(s1); string s2 = s1.replaceall("|","1"); // 输出 1|1 system.out.println(s2); string s3 = "<mfenced separators=\"|\">"; string s4 = s3.replaceall("<mfenced separators=\"|\">","2"); // 这个输出 2|2 system.out.println(s4); // 所以以后复杂的公式匹配 | ,就先将|替换掉,再进行匹配 string s5 = s1.replaceall("\\|", "1"); // 输出 1 system.out.println(s5); string s6 = s3.replaceall("<mfenced separators=\"\\|\">", "2"); // 输出 <mfenced separators="|"> system.out.println(s3); // 如果想将s3替换为2,如何操作 string s7 = s3.replaceall("\\|", "竖"); s7 = s7.replaceall("<mfenced separators=\"竖\">","2"); // 输出 2 system.out.println(s7);