我有 javascript 正则表达式来提取所有 <img>
具有 src
的标签如http://....
来自字符串。
regex = /<img[^>]+src="?(http:\/\/[^">]+)"?\s*\/>/g;
我的问题是如何在Java中执行此操作,其次上面的正则表达式仅给出src
的内容,我想提取并替换整个<img>
带有空格。
最佳答案
//Try this solution:
//This answer was tested I hope it is what you're looking for :
Pattern p = Pattern.compile("<img?(.+)?\\s*\\/>");
Matcher m = p.matcher("<img src=\"http://google.com\"/>");
if(m.find())
System.out.println(m.group(1));
关于java - 正则表达式查找所有带有 http url 的 img 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24774757/