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() 方法替换括号?例如,如果我有字符串"[][]teststring]]]]",我想使用 replaceAll() 将其减少为“teststring”。
"[][]teststring]]]]"
假设您只想摆脱方括号:
String output = "[][]teststring]]]]".replaceAll("[\\[\\]]", "");
我还建议您查看正则表达式文档。
return yourWord.replaceAll("\\[","").replaceAll("\\]","")
JavaDocs