我有一個模式@@{}
並給定了一個字符串,我需要找出所有大括號之間進入的字符串。通過匹配給定字符串中的模式獲取字符串數組
例子: 如果我的字符串是Hi This is @@{first} and second is @@{second} along with third @@{third} string
我期望的輸出是一個字符串數組組成元素:
first
second
third
這個我的Java代碼爲:
Pattern p = Pattern.compile("\\@\\@\\{(.+?)\\}");
Matcher match = p.matcher("Hi This is @@{first} and second is @@{second} along" +
"with third @@{third} string");
while(match.find()) {
System.out.println(match.group());
}
但我得到的輸出是
@@{first}
@@{second}
@@{third}
請指導我如何得到需要的結果和我在做什麼錯誤
順便說一句,看看你以前的問題......如果一個答案解決了你的問題,不要忘記在左邊勾上綠色的選中標記,將其標記爲「接受」。 – Jonik 2009-11-10 07:51:20
+1非常明確的書面問題 – 2009-11-10 08:54:31