Uma*_*til 6 html java string android
我试图从给定的字符串中获取HTML图像标记网址.应该有一些正则表达式来获得它.但不知道该怎么做.谁可以帮我这个事.
例如
I have string like this with <br> some HTML<b>tag</b>
with <img src="http://xyz.com/par.jpg" align="left"/> image tags in it.
how can get it ?
Run Code Online (Sandbox Code Playgroud)
我只想要来自字符串的http://xyz.com/par.jpg
请参阅此问题以供参考.基本上它说使用:
String imgRegex = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
Run Code Online (Sandbox Code Playgroud)
我使用jsoup。它非常易于使用且重量轻。有些版本与 Java 1.5 不兼容,但似乎他们解决了这个问题。
String html = str;
Document doc = Jsoup.parse(html);
Elements pngs = doc.select("img[src$=.png]"); // img with src ending .png
Run Code Online (Sandbox Code Playgroud)