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.
我正在尝试使用正则表达式去除字符串上所有不需要的字符,例如空格“”、点“.”、破折号“-”和“The”
比如《黑暗骑士崛起》。并输出“DarkKnightRises”
这只是我得到的
.replaceAll("\\s+", "")
我是个十足的菜鸟,
想法?
谢谢
您可以使用:
String str = "The Dark-Knight Rises."; String repl = str.replaceAll("(?i)[ .-]+|\\bthe\\b", ""); //=> DarkKnightRises