从包含< img src>的Java String中提取url标签 [英] Extract url from Java String containing <img src> tag
本文介绍了从包含< img src>的Java String中提取url标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望提取以下字符串:
http://www.01net.com/images/article/mea/150.100.790233.jpg
此字符串是网址的网址以下Java字符串中的第一个元素标记:
This string is the url of the first element tag in the following Java string :
<img src="http://www.01net.com/images/article/mea/150.100.790233.jpg" width="150" height="100" border=0 alt="" align=left style="margin-right:10px;margin-bottom:5px;">A en croire CNet US, le gouvernement américain aurait cherché à obtenir les master keys de plusieurs acteurs du Web pour pouvoir déchiffrer les communications de leurs utilisateurs, protégées par le protocole SSL.<img width='1' height='1' src='http://rss.feedsportal.com/c/629/f/502199/s/2f34155b/mf.gif' border='0'/><div class='mf-viral'><table border='0'><tr><td valign='middle'><a href="http://share.feedsportal.com/share/twitter/?u=http%3A%2F%2Fwww.01net.com%2Feditorial%2F600625%2Fchiffrement-sur-le-web-fbi-et-nsa-voulaient-obtenir-les-cles-ssl-de-geants-du-net%2F%23%3Fxtor%3DRSS-16&t=Chiffrement+sur+le+Web%2C+FBI+et+NSA+voulaient+obtenir+les+cl%C3%A9s+SSL+de+g%C3%A9ants+du+Net" target="_blank"><img src="http://res3.feedsportal.com/social/twitter.png" border="0" /></a> <a href="http://share.feedsportal.com/share/facebook/?u=http%3A%2F%2Fwww.01net.com%2Feditorial%2F600625%2Fchiffrement-sur-le-web-fbi-et-nsa-voulaient-obtenir-les-cles-ssl-de-geants-du-net%2F%23%3Fxtor%3DRSS-16&t=Chiffrement+sur+le+Web%2C+FBI+et+NSA+voulaient+obtenir+les+cl%C3%A9s+SSL+de+g%C3%A9ants+du+Net" target="_blank"><img src="http://res3.feedsportal.com/social/facebook.png" border="0" /></a> <a href="http://share.feedsportal.com/share/linkedin/?u=http%3A%2F%2Fwww.01net.com%2Feditorial%2F600625%2Fchiffrement-sur-le-web-fbi-et-nsa-voulaient-obtenir-les-cles-ssl-de-geants-du-net%2F%23%3Fxtor%3DRSS-16&t=Chiffrement+sur+le+Web%2C+FBI+et+NSA+voulaient+obtenir+les+cl%C3%A9s+SSL+de+g%C3%A9ants+du+Net" target="_blank"><img src="http://res3.feedsportal.com/social/linkedin.png" border="0" /></a> <a href="http://share.feedsportal.com/share/gplus/?u=http%3A%2F%2Fwww.01net.com%2Feditorial%2F600625%2Fchiffrement-sur-le-web-fbi-et-nsa-voulaient-obtenir-les-cles-ssl-de-geants-du-net%2F%23%3Fxtor%3DRSS-16&t=Chiffrement+sur+le+Web%2C+FBI+et+NSA+voulaient+obtenir+les+cl%C3%A9s+SSL+de+g%C3%A9ants+du+Net" target="_blank"><img src="http://res3.feedsportal.com/social/googleplus.png" border="0" /></a> <a href="http://share.feedsportal.com/share/email/?u=http%3A%2F%2Fwww.01net.com%2Feditorial%2F600625%2Fchiffrement-sur-le-web-fbi-et-nsa-voulaient-obtenir-les-cles-ssl-de-geants-du-net%2F%23%3Fxtor%3DRSS-16&t=Chiffrement+sur+le+Web%2C+FBI+et+NSA+voulaient+obtenir+les+cl%C3%A9s+SSL+de+g%C3%A9ants+du+Net" target="_blank"><img src="http://res3.feedsportal.com/social/email.png" border="0" /></a></td><td valign='middle'></td></tr></table></div><br/><br/><a href="http://da.feedsportal.com/r/172449334514/u/218/f/502199/c/629/s/2f34155b/kg/342/a2.htm"><img src="http://da.feedsportal.com/r/172449334514/u/218/f/502199/c/629/s/2f34155b/kg/342/a2.img" border="0"/></a><img width="1" height="1" src="http://pi.feedsportal.com/r/172449334514/u/218/f/502199/c/629/s/2f34155b/kg/342/a2t.img" border="0"/>
推荐答案
不要浪费模式的资源,只需使用:
如何运作:
Instead of wasting ressources with Patterns, simply use this:
How it works:
-
所有
是全部您要搜索的文字 -
s
是要查找的开始模式,在这种情况下,它将是第一个
-
ix
是所有
- 中网址的位置
最后一行从
所有
获取字符串,从ix
开始到下一个
all
is the whole text you want to search fors
is the start pattern to look for, in this case it will be the firstix
is the position of the URL inall
the last line gets the String from
all
starting atix
to the next"
it finds
String all = "<img src=\"http://www.01net.com/images/article/mea/150.100.790233.jpg\""; // shortened it
String s = "<img src=\"";
int ix = all.indexOf(s)+s.length();
System.out.println(all.substring(ix, all.indexOf("\"", ix+1)));
这篇关于从包含< img src>的Java String中提取url标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文