在字符串中查找所有图像src url并存储在数组中 [英] Find all image src url in string and store in array

查看:103
本文介绍了在字符串中查找所有图像src url并存储在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var rawString = '<a>This is sample</a><img src="example1.com" /></br><img src="example2.com" /><p>String ends.</p>'

var output = somefunction(rawString);

输出应为:


output = [example1.com,example2.com];

output = ["example1.com","example2.com"];

我没有找到任何解决方案在这我尝试使用一些正则表达式但无法正常工作。

I didn't find any solution here. I tried using few regex but couldn't work perfactly.

这里有stackoverflow几个答案:

Here are stackoverflow few answers:

https://stackoverflow.com/a/12393724/4203409

https://stackoverflow.com/a/25632187/4203409

提前致谢。

推荐答案

您可以使用 jQuery() .filter() .map() .get()

var output = $(rawString).filter("img").map(function() {return this.src}).get();

这篇关于在字符串中查找所有图像src url并存储在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆