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.
我有一个字符串m="hell,hj;nk,.txt"
m="hell,hj;nk,.txt"
我想要我的字符串作为字符串m="hellhjnk.txt"
m="hellhjnk.txt"
我在用:
Pattern p=Pattern.compile("(\"([^\"]*)(\\.)([a-z]{1,4}[\"]))|'([^']+)(\\.)([a-z]{1,4})'");
它适用于双引号和扩展名。如何删除空格、逗号、分号?
你可以这样做:
m = m.replaceAll("[,; ]","");
该类Pattern用于匹配。你基本上可以做同样的事情:
Pattern
Pattern p = Pattern.compile("[;, ]"); String m = "hell,hj;nk,.txt"; Matcher matcher = p.matcher(m); System.out.println(matcher.replaceAll(""));