给定URL(单行):http:
//test.example.com/dir/subdir/file.html
如何使用正则表达式提取以下部分:
即使我输入以下URL,正则表达式也应该正常工作:
http://example.example.com/example/example/example.html
Run Code Online (Sandbox Code Playgroud) 我需要一个正则表达式来验证javascript中的图像文件扩展名.你是否有一个 ?
我想使用jquery检查给定URL上是否存在图像.例如,如何检查此URL上是否存在图像.
https://www.google.com/logos/2012/hertz-2011-hp.gif
Run Code Online (Sandbox Code Playgroud)
但不是这个网址
http://www.google.com
Run Code Online (Sandbox Code Playgroud) 我想从网页的HTML源代码中获取所有图片网址的列表(abosulte和相对网址).我使用Jsoup来解析HTML,但它没有给出所有图像.例如,当我解析google.com HTML源时,它显示零图像..在google.com中HTML源图像链接在表单中..
"background:url(/intl/en_com/images/srpr/logo1w.png)
在rediff.com中,图片链接的形式是..
videoArr[j]=new Array("http://ishare.rediff.com/video/entertainment/bappi-da-the-first-indian-in-grammy-jury/2684982","http://datastore.rediff.com/h86-w116/thumb/5E5669666658606D6A6B6272/v3np2zgbla4vdccf.D.0.bappi.jpg","Bappi Da - the first Indian In Grammy jury","http://mypage.rediff.com/profile/getprofile/LehrenTV/12669275","LehrenTV","(2:33)");
j = 1
videoArr[j]=new Array("http://ishare.rediff.com/video/entertainment/bebo-shahid-jab-they-met-again-/2681664","http://datastore.rediff.com/h86-w116/thumb/5E5669666658606D6A6B6272/ra8p9eeig8zy5qvd.D.0.They-Met-Again.jpg","Bebo-Shahid : Jab they met again!","http://mypage.rediff.com/profile/getprofile/LehrenTV/12669275","LehrenTV","(2:17)");
所有图像都没有在"img"标签中.我还想提取在"img"标签中甚至没有的图像,如上面的HTML源代码所示.
我怎么能这样做??请帮我这个..谢谢
我已经使用HtmlAgilityPack解析页面,并获得大多数img源代码.然而,许多网站在img src属性以外的地方包含img url(例如内联javascript,不同的属性,不同的元素).我想投一个稍宽的网并在整个html字符串上运行一个正则表达式,在正则表达式中捕获以下内容.
我想这写起来很简单,但我不是一个很棒的正则表达式.我想这些部件看起来像这样
任何人都可以帮助我填补空白吗?
谢谢
回答
(https?:)?//?[^\'"<>]+?\.(jpg|jpeg|gif|png)
Run Code Online (Sandbox Code Playgroud) 如何使用jquery获取并检查href路径是否包含图像路径或其他链接. 例如:
<a href="image.png"><img src="image.png"/></a>
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,锚文本包含图像src,然后只有jquery函数才能找到href path.ie,href仅当锚文本包含img标记时才获取路径.
我查看了.hasjquery api来检查图像.但是我如何检查href是否包含图像路径或其他路径.根据SO用户的建议我要做的事情,比如.
<script type="text/javascript">
jQuery(document).ready(function($) {
if (jQuery('a').has("img")) { // it return the no. of img tag within a
jQuery('a').has("img").prop('href', '#');
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
请参阅上面的脚本执行操作以检查锚文本是否包含图像标记,然后仅检查锚标记的href链接.以同样的方式添加喜欢做上面的脚本来检查href是否包含任何图像路径或链接.如果图像路径包含在href上,则应执行上述脚本,否则不执行.
@Downvoters的任何可能原因.?
是否可以在jquery中做,任何建议将非常感谢.
regex ×3
image ×2
javascript ×2
jquery ×2
c# ×1
html ×1
java ×1
jquery-ui ×1
url ×1
validation ×1