【发布时间】:2014-06-15 10:33:32
【问题描述】:
我正在尝试将 java 正则表达式应用于以下文本以提取内容,但问题是,当文本中只有一个 href 时,它发现内容很好,但当有更多时,它会转到文本的结尾。这是正则表达式模式:
Pattern pattern = Pattern.compile("\\\"\\>(.*)\\</a\\>\\<br\\>", Pattern.DOTALL);
这是正文:
<div><b>Attachments:</b> <a href="http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/1.JPG">http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/1.JPG</a><br><a href="http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/yinYang.gif">http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/yinYang.gif</a><br><a href=""></a></div>
所以如果只有 1.JPG 的 href,那么它会找到正确的答案:
http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/1.JPG
但是当我添加 yinYang.gif 时,如果找到以下内容:
">http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/1.JPG</a><br><a href="http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/yinYang.gif">http://projectspace.intranet.group/sites/CFY366N/Lists/Deliverables/Attachments/8/yinYang.gif</a><br>
如何更改此设置以查找不同组中<a> ...</a> 之间的所有值。
【问题讨论】: