java中的正则表达式如何获得以下输出

时间:2014-09-19 12:19:31

标签: java

我需要一个正则表达式来提取内容,以href =开头到括号的末尾。。我如何在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"

1 个答案:

答案 0 :(得分: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