Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我使用以下代码用空格替换电话号码+符号时,然后生成异常
代码:
phonenum.replaceAll("+","");
例外:
java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 1:
请帮我。
该replaceAll方法似乎使用了正则表达式,所以我猜它会失败,因为+它不是一个有效的正则表达式,+必须有一些东西要重复。
replaceAll
+
尝试phonenum.replaceAll("\\+","")转义它并匹配文字“+”。
phonenum.replaceAll("\\+","")