Suppose I have正则表达式来获得<a href> from a string in java
<img class="size-full wp-image-10225" alt="animals" src="abc.jpg"> blah blah blah
<a href="http://en.wikipedia.org/wiki/Elephant">elephant is an animal</a> blah
I want a regex to give me the output :
blah blah blah <a href="http://en.wikipedia.org/wiki/Elephant">elephant is an animal</a> blah
without the
. I can do str.replace(" ","")
separately, but how do I get the string starting from blah blah...
until blah
(which includes link tag).
您必须单独删除'img'标签。你只需要a-Tag?这与RegExpr一起工作。如果您想在标签前后获得其他文本,请在此处遇到问题。为什么你不容易删除不需要的标签? –
我确实需要标签之前的文字。所以基本上我不能说StringUtils.removeHTMLTags(),因为这将删除所有的标签,我想要的HTML标签。所以基本上我在想什么是找到ahref之前的第一个“>”,然后从那里捕获文本,直到(含) – user3298846
_Sees正则表达式和HTML在title_“http://stackoverflow.com/a/1732454/2846923 “。 –