2012-08-22 138 views

回答

2
String s = "ERR|appLogger|[Manager|Request]RequestFailed[com.package.file]uploading[com.file]"; 
Pattern pattern = Pattern.compile("\\[([A-Za-z0-9.]+)\\]"); 
Matcher m = pattern.matcher(s); 
if (m.find()) { 
    System.out.println(m.group(1)); // com.package.file 
} 
+0

這解決了我的問題。但我想改變,現在我得到的方括號also.I要提取文本,不需要外廣場brackets.that意味着我需要「融爲一體。 package.file「而不是」[com.package.file]「 – RP89

+0

@RemyaPoulose:將括號拉到捕獲組」\\ [([A-Za-z0-9。+])\\]'外面。 –

0

中的東西的行提取「com.package.file」:

^\w+\|\w+\|\[\w+\|\w+\]\w+\[([\w\.]+)\]\w+\[[\w\.\_]+\]$ 

將允許您拍攝。

Pattern pattern = Pattern.compile("^\\w+\\|\\w+\\|\\[\\w+\\|\\w+\\]\\w+\\[([\\w\\.]+)\\]\\w+\\[[\\w\\.\\_]+\\]$", Pattern.CASE_INSENSITIVE); 
Matcher matcher = pattern.matcher("ERR|appLogger|[Manager|Request]RequestFailed[com.package.file]uploading[com.file_upload]"); 
System.out.println(matcher.group(1));