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.
我想使用字符串的replaceAll函数来删除任何不在给定集合中的字符。我试过
replaceAll
x = x.replaceAll("^[A-Za-z]", "");
但是这不起作用,因为当放在表达式的开头时,^ 字符有另一个含义(匹配行的开头)。
我怎样才能得到我想要的行为?我找不到有关正确语法的任何帮助。
谢谢
x = x.replaceAll("[^A-Za-z]", "");
它应该在括号内。
你在寻找范围的否定吗?然后它必须在括号内。
更多在Java 文档中。