1
可以說我有串這樣的:如何獲得在括號中的字符串與Java數組
String q = "foo (one) bla (two) zoo key hola (tree) (four) five"
我想在括號中的字符串提取到字符串數組
so this would be true:
stringArray[3].equals("four")
有東西在普通包或其他技巧來做到這一點?
可以說我有串這樣的:如何獲得在括號中的字符串與Java數組
String q = "foo (one) bla (two) zoo key hola (tree) (four) five"
我想在括號中的字符串提取到字符串數組
so this would be true:
stringArray[3].equals("four")
有東西在普通包或其他技巧來做到這一點?
Pattern p = Pattern.compile("\\((.*?)\\)");
Matcher m = p.matcher("abc (one) abc (two) abc");
List<String> result = new ArrayList<String>();
while(m.find())
result.add(m.group(1));
很容易嘗試「這個工作」的問題......難以忍受-1。 – 2011-06-19 06:20:10