2014-09-19 15 views
-4

我需要一個正則表達式來提取內容開始與href =括號結束]。我該怎麼做在java中。在Java中的正則表達式如何獲取下面的輸出

String s= [a href="http://myimagefactorycollection.files.wordpress.com/2014/09/ 
    2db83fcf95c5fc036a00abfb412f50e4.jpg"][a href="https://myimagefactorycollection.files.wordpress.com/2014/09/0e397a47f88e18f8fb91d17db18c7edd-copy.jpg"] 

The output should be 
"http://myimagefactorycollection.files.wordpress.com/2014/09/ 
    2db83fcf95c5fc036a00abfb412f50e4.jpg" 
"https://myimagefactorycollection.files.w 
ordpress.com/2014/09/0e397a47f88e18f8fb91d17db18c7edd-copy.jpg" 
+0

你嘗試過什麼?我只能說String類有方法來查找特定字符的索引並剪切一個子字符串。所以請繼續。 – 2014-09-19 12:26:03

+1

您有29個問題,其中包括4個重複的問題,未接受答案,未能顯示任何結果。這讓我想起了你:http://slash7.com/2006/12/22/vampires/ – 2Dee 2014-09-19 12:26:44

+0

[Java正則表達式的以下內容]的可能重複(http://stackoverflow.com/questions/25931706/java -out-of-the-content- – Jaguar 2014-09-19 12:33:53

回答

0
Pattern p = Pattern.compile(".*\\\"(.*)\\\".*"); 
Matcher m = p.matcher(yourString); 
while (m.find()) { 
    System.out.println(m.group(1)); 
} 

釋:

.* - anything 
\\\" - quote (escaped) 
(.*) - anything (captured) 
\\\" - another quote 
.* - anything 

瞭解更多關於正則表達式here

+0

給沒有任何解釋的代碼解決方案給沒有顯示任何努力的人是,恕我直言,沒有幫助,甚至沒有他... – 2Dee 2014-09-19 12:29:26